Różnice

Różnice między wybraną wersją a wersją aktualną.

Odnośnik do tego porównania

pl:prolog:pllib:oo_interpreter [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 +====== Oo interpreter ======
 +{{tag>​OOP interpreter}}
 +===== Description =====
 +A simple interpreter for object-oriented programs.
 +
 +**Source**: ​ PROLOG programming for artificial intelligence,​ 3rd Edition, Harlow, 2001, ISBN 0-201-40375-7.
 +===== Download =====
 +Program source code: {{oo_interpreter.pl}}
 +===== Listing =====
 +<code prolog>
 +%  Figure 23.5  A simple interpreter for object-oriented programs.
 +
 +
 +%  An interpreter for object-oriented programs
 +
 +%  send( Message, Object) ​ if
 +%    find Object'​s methods and 
 +%    execute the method that corresponds to Message
 +
 +send( Object, Message) ​ :-
 +  get_methods( Object, Methods), ​            % Find Object'​s methods
 +  process( Message, Methods). ​               % Execute corresponding method
 +
 +get_methods( Object, Methods) ​ :-
 +  object( Object, Methods). ​                         % Private methods
 +
 +get_methods( Object, Methods) ​ :-
 +  isa( Object, SuperObject), ​         ​
 +  get_methods( SuperObject,​ Methods). ​               % Inherited methods
 +
 +process( Message, [Message | _]).                    % Use a fact
 +
 +process( Message, [ (Message ​ :-  Body) | _])  :-    % Use a rule
 +  call( Body).
 +
 +process( Message, [_ | Methods]) ​ :-
 +  process( Message, Methods).
 +</​code>​
 +===== Comments =====
  
pl/prolog/pllib/oo_interpreter.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0