Re: Prolog OOP (prologonlinereference.org)



Yes, I think the approach is the same.
In particular:

:- module('$list', []).
object(List) :-
is_list(List).
member(Element) :-
:object(List),
member(Element, List).

There are two differences:
1) here a call like this(This) will unify This with '$list' (i.e. with the
current module, or class), while object/1 is used as a container of data;
2) in logtalk object/1 is a directive, here it is a predicate, so you can
define a body (perhaps to throw exceptions on type checking).

It is a surprise to see how the same things can be done with so different
background.
Thank you Paulo for the reply. I really do not want to compare this didactic
oop with LogTalk.

Cheers - /\/\


"Paulo Moura" <pjlmoura@xxxxxxxxx> ha scritto nel messaggio
news:1150703684.008413.272500@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Mauro DiNuzzo wrote:
...
For example, system can be configured in order to allow things like the
following:

| ?- [1,2,3]:length(L).
L = 3
yes

In other Prolog object-oriented extensions (e.g. OL(P), L&O, SICStus
Objects, or Logtalk) similar functionality is achieved using parametric
objects, which allows you to associate predicates with compound terms
(such as ./2 above). For example, in Logtalk you would write:

:- object(.(_, _)). % note that the [X, Y, ...] notation
% is just syntactic sugar for ./2

:- public(member/1).

member(Element) :-
this(List),
member(Element, List).

member(Element, [Element| _]).
member(Element, [_| Tail]) :-
member(Element, Tail).

:- end_object.

Compiling and loading this object allows similar queries to your
example above:

?- [1,2,3]::member(X).

X = 1 ;
X = 2 ;
X = 3 ;
No


Cheers,

Paulo



.