Oo 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

%  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).

Comments

pl/prolog/pllib/oo_interpreter.txt · ostatnio zmienione: 2017/07/17 08:08 (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