Re: substructure sharing in #'union result
- From: Pascal Costanza <pc@xxxxxxxxx>
- Date: Tue, 20 Nov 2007 11:30:15 +0100
andrew.polonsky@xxxxxxxxx wrote:
Hi, I am new to LISP, so I apologize if this is a silly question!
I am wondering if there are any general patterns on when the list
returned by the union function will share substructure with its
arguments. Also, will it be eq to one of them iff the other is nil?
Cltl and the spec don't seem to say anything about this :(
(If it's of interest, the context is this. I am parsing logical
formulas. At each syntax node I have (among other things) a list of
variables free for that subformula. This will be the union of those
in its children. IF I KNEW that the union would preserve the
pointers, I could implement a simple binding mechanism by only
(rplac)ing the leafs in the tree. Alternatively, I could do
substitution explicitly, but then I wanna know what happens to those
lists of variables!)
The entries in sets can be more complex objects than just plain symbols. Just put CLOS objects representing variables in your sets and modify some slot representing a binding in each object. The CLOS notion of unbound slots is even a pretty direct and appropriate way of representing free variables.
Union uses #'eql for comparison by default, which respects object identity. So the union of two lists is guaranteed to contain the same objects (under #'eql) as the original lists. This means that side effecting slots in those objects gives you the semantics you want, no matter how union works.
Pascal
--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
.
- Follow-Ups:
- Re: substructure sharing in #'union result
- From: andrew . polonsky
- Re: substructure sharing in #'union result
- References:
- substructure sharing in #'union result
- From: andrew . polonsky
- substructure sharing in #'union result
- Prev by Date: Re: So what is the right way to write string.join?
- Next by Date: Re: Can non-Lisp files be dependencies in asdf or mk:defsystem?
- Previous by thread: substructure sharing in #'union result
- Next by thread: Re: substructure sharing in #'union result
- Index(es):
Relevant Pages
|
Loading