Recursive parametric object specification?

Suggestions for new Logtalk features

Moderator: Paulo Moura

Post Reply
RandyHelzerman
Posts: 1
Joined: Tue Jul 28, 2009 4:39 pm

Recursive parametric object specification?

Post by RandyHelzerman » Tue Jul 28, 2009 6:09 pm

Hi, I love being able to do things like:

Code: Select all

:-begin_object(point(_X,_Y)).
     get_x(X) :- this(point(X,_)).
:-end_object.
But I would also like to be able to do similar things for more recursive data structures. For example, something like this:

Code: Select all

:-begin_object(list).
:-object([]).
:-object([_|T]), list(T).   % yeah this is ugly, just want to specify the recursive structure
    append(Y,Z) :-
            this(X),
             list::append(X,Y,Z).
:-end_object.
then we could do things like say [1,2]::append([3,4],Z).

For lists, this might be overkill, but suppose you wanted to define an object which was a red-black tree, or another more complex recursive structure....

Anyways, would this make sense, or are there better ways to do it already available?

Paulo Moura
Logtalk developer
Posts: 474
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Recursive parametric object specification?

Post by Paulo Moura » Tue Jul 28, 2009 6:41 pm

See the "parametric" example in the current Logtalk distribution for a programming example of defining lists as a parametric object:

http://trac.logtalk.org/browser/trunk/e ... metric.lgt
Paulo Moura
Logtalk developer

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest