Re: substructure sharing in #'union result



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/
.



Relevant Pages

  • SQL Injection: Issue with UNION SELECT ALL
    ... using a UNION SELECT ALL statement. ... an equal number of expressions in their target lists. ... Column 'a.id' is invalid in the select list because it is not contained ... in an aggregate function and there is no GROUP BY clause. ...
    (Pen-Test)
  • Re: substructure sharing in #union result
    ... REMOVING the references to variables from those lists when they get ... This will be the union of those ... Just put CLOS objects representing variables in your sets and modify ...
    (comp.lang.lisp)
  • RE: report that includes multi tables
    ... report by last name and not have to go through each report by year, ... The next question I have is how to do a UNION instead of a JOIN. ... You couldn't join the two lists because ... >> is auto generated. ...
    (microsoft.public.access.gettingstarted)
  • Re: substructure sharing in #union result
    ... REMOVING the references to variables from those lists when they get ... This will be the union of those ... Just put CLOS objects representing variables in your sets and modify ...
    (comp.lang.lisp)
  • Re: A Faster Way...
    ... > wxPython code that uses a lot of string concatenation (and uses these ... > If I simplify the problem, suppose I have 2 lists like: ... > What I would like to have, is a "union" of the 2 list in a single tuple. ... It'd be one heck of a short homework assignment. ...
    (comp.lang.python)

Loading