[Prev][Next][Index][Thread]
Re: A Proposal!!
On Sun, 21 May 2000 22:00:02 -0400 (EDT), brucehoult@pobox.com (Bruce Hoult)
wrote:
> In article <uvqitw7jsyw.fsf@ernie.ai.mit.edu>, gregs@ai.mit.edu (Gregory
> T. Sullivan) wrote:
>
> > Why not say that all !'ed versions _must_ maintain eq?-ness and all
> > non-!'ed versions _never_ side-effect the existing object?
>
> Because that's silly.
That's Java. :-j
>
> How are you going to do that with a list? The efficient thing to do with
> a list is to create a cons cell, put the new data in it, point it at the
> existing list, and return the new cell. The only way to make it == the
> existing list would be to traverse the list down to the end and add the
> new element there. Or at least add it as the second element.
>
> Making add! return an == thing on a non-stretchy vector is plain impossible.
Well, Java does this via an extra layer of indirection. In Dylan it might be
something like:
define class <list>! ( <some-suitable-abstract-sequence> )
slot %list :: <list> = #();
end class;
define method add! ( l :: <list>!, e :: <object> ) => ( l :: <list>! )
%list( l ) := pair( e, %list( l ) );
l
end method;
define method first ( l :: <list>! ) => ( e :: <object> )
head( %list( l ) );
end method;
One advantage of this is that the wrapper instance <list>! could hold on to
more than the head of the actual list. E.g. one can hold on to the tail and so
make consing on to both ends relatively efficient.
define method add-last! ( l :: <list>!, e :: <object> ) => ( l :: <list>! )
tail( %last( l ) ) := pair( e, #() );
l
end method;
>
> The way it is now is fine and comes from a long history of LISP
> programing. Wihtout ! is pure functional -- doens't affect the arguments
> -- and with ! is allowed to do whatever it wants with whatever is fastest
> being king.
This form of list also has a tradition in Lisp programming: cf tcons and tconc.
__Jason
_____________________________________________________________________
This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit
http://www.star.net.uk/stats.asp
Follow-Ups:
References: