home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / prolog / 2086 < prev    next >
Encoding:
Text File  |  1992-11-15  |  3.2 KB  |  101 lines

  1. Newsgroups: comp.lang.prolog
  2. Path: sparky!uunet!mcsun!news.funet.fi!aton.abo.fi!usenet
  3. From: HVIRTANEN@finabo.abo.fi (Harry Virtanen INF)
  4. Subject: Object Prolog
  5. Message-ID: <1992Nov16.103244.28734@abo.fi>
  6. Sender: usenet@abo.fi (Usenet NEWS)
  7. Organization: Abo Akademi University, Finland
  8. Date: Mon, 16 Nov 1992 10:32:44 GMT
  9. X-News-Reader: VMS NEWS 1.23
  10. Lines: 89
  11.  
  12. Hi!
  13.  
  14. There has been some discussion on Object Prolog in this newsgroup. I have
  15. programmed (in prolog), just for the fun of it, an Object Prolog interpreter
  16. that at the moment supports:
  17.  
  18. 1) an object with its associated set of methods and attributes.
  19. 2) "dynamic objects"
  20. 3) a demon 'demon(Object,Attribute)' which, if it exists, will react to a 
  21.    change in the value of the Attribute in the Object.
  22. 4) a special object 'myself' which enables to send a message from a method to
  23.    the object in which the method was declared.
  24. 5) a demon called 'init' which, if present in the set of methods of an object,
  25.    will be activated when a new instance of the object is created.
  26. 6) an inheritance network
  27. 7) multiple inheritance. An object may inherit the methods and attributes from
  28.    several parent objects.
  29. 8) message passing between objects. Search for an appropriate method is
  30.    depth-first.
  31. 9) Objects as values to attributes. Does not however support recursive 
  32.    attributes, nor two objects that refer to each other through their 
  33.    attributes.
  34.  
  35. and here is a stupid example:
  36.  
  37. animal
  38.      with_attributes
  39.          [(age:0)]
  40.      with_methods
  41.          [(setage(Age):-
  42.                  age:Age),
  43.           (show:-
  44.                  age:Age, write(Age),nl)].
  45.  
  46. bird
  47.      with_attributes
  48.          [(skin:feathers),
  49.           (name:unknown)]
  50.      with_methods
  51.          [(init:-
  52.                  write('A bird has been born'),nl),
  53.           (fly(Me,Tree):-
  54.                  write('Im flying to a tree'),nl,
  55.                  ontree(Me) send_to Tree)].
  56. bird is_a animal.
  57.  
  58. tree
  59.      with_attributes
  60.          [(inhabitant:bird)]
  61.      with_methods
  62.          [(ontree(What):-(inhabitant:bird:name):What)].
  63.  
  64. demon(tree,(inhabitant:bird:name)):-
  65.      (inhabitant:bird:name):Value,
  66.      write('The name of the inhabitant of the tree has changed to '),
  67.      write(Value),nl. 
  68.  
  69. test:-
  70.       use_objects,
  71.       new_instance(theNightHawk,bird),        % new bird
  72.       new_instance(oak,tree),            % new tree
  73.       ontree(Whats) send_to oak,                % whats on the tree
  74.       write(Whats),write(' is on the tree'),nl,
  75.       fly(theNightHawk,oak) send_to theNightHawk, % make the bird fly, hmm?
  76.                                                   % this I have to work on
  77.       show send_to theNightHawk,        % show age of nighthawk
  78.       setage(30) send_to theNightHawk,        % set his age to 30
  79.       show send_to theNightHawk,        % check age
  80.       ontree(What) send_to oak,            % what is now on the oak
  81.       write(What),write(' is on the tree'),
  82.       clear_all.
  83.                         
  84. The output of the test program will (suprise, suprise) be:
  85.  
  86. A bird has been born
  87. unknown is on the tree
  88. Im flying to a tree
  89. The name of the inhabitant of the tree has changed to theNightHawk
  90. 0
  91. 30
  92. theNightHawk is on the tree
  93.  
  94.  
  95. Comments and questions are wellcome!
  96.  
  97. Harry "the bird" Virtanen
  98. Abo Akademi University
  99. Abo, Finland
  100.  
  101.