Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!uunet!newsflash.concordia.ca!CC.UMontreal.CA!IRO.UMontreal.CA!tarau
From: tarau@IRO.UMontreal.CA (Paul Tarau)
Subject: Re: [Q] OO implementation
Message-ID: <D60KF0.78H@IRO.UMontreal.CA>
Sender: news@IRO.UMontreal.CA
Organization: Universite de Moncton, Canada
References: <3krgjh$m3t@erinews.ericsson.se>
Date: Sat, 25 Mar 1995 20:47:24 GMT
Lines: 56

In article <3krgjh$m3t@erinews.ericsson.se> ehsjony@ehs.ericsson.se writes:
>
>I have a question on how to implement object oriented support in prolog. 
>............
>How can object state alteration be implemented?
............
>Using Sicstus prolog with its builtin predicate setarg/3:
>
>alter_setarg(Ob, ArgNo, NewVal) :- setarg(ArgNo, Ob, NewVal).
>
>(Is the setarg/3 predicate available in other prolog implementations?)
>
>
>Are there better ways to alter an object's state? 


Setarg/3 is available with the same semantics as in Sicstus, although
with a somewhat faster implementation in BinProlog 3.30 (using a
value-trailing technique with local-reuse for deterministic branches).

Other Prologs which have it, with a similar semantics are
Aquarius and WAMCC.  Equivalent (but arguably cleaner) facilities are
available in Wild-Life 1.01 and Lambda-Prolog-MALI.

Higher level constructs, usually combined with backtrackable  and permanent
global objects (global variables in Wild-Life or a hashing based blackboard in
BinProlog) should be used to implement objects efficiently. 
My preferences go for the use of intuitionistic and linear implication as
described in various papers by Dale Miller and others.  Their main
(practical only!) problem is that no concept of failure-surviving
objects can be implemented on top of them.

In BinProlog 3.30 linear and intuitionistic implication actually hide
efficient internal setarg/3 + implicit global state processing
and it can be combined with permanent state information stored
in a sequential or in a Linda-based multi-threaded blackboard.
A larger set of linear operators are available in the Lolli language by
J. Hodas.

Some preprocessor based state information handling techniques are also
worth to be considered. One of the best I know of is accumulator
processing in Wild-Life (based on Peter VanRoy's Extended DCGs), which
allows keeping state information and state-transition methods in hidden
extra arguments added by a preprocessor.

For _very_ efficient state processing, _without_ a preprocessor,
BinProlog 3.30 has also a set of extended DCG-style hidden accumulator
handling builtins written in C (`invisible grammars') allowing transparent
use of multiple DCG streams.

BinProlog 3.30 is available from clement.info.umoncton.ca for various
Unix platforms (I have recently added a binary for MIPS based SGI
machines). Please see the comp.lang.prolog FAQ for other sites where
the software I have referred to is (all freely!) available.

Paul Tarau
