Re: possibly silly question re quoting of function arguments...



keke@xxxxxxx (Takehiko Abe) writes:

Peter Seibel wrote:

Basically you can't do what you think you want to do. The good news is
that when you step back and explain what you're really trying to do
(i.e. why do you think you need to do this) someone here will be able
to tell you the Lispy way to do *that*.

He wants to distinguish two lists -- possibly empty ones.
It is not obvious why two empty lists are EQ:

* (eq (list) (list)) --> T

While this works:

(defvar *place-1* (make-array 0 :adjustable t :fill-pointer 0))
(defvar *place-2* (make-array 0 :adjustable t :fill-pointer 0))

(defun place-1-p (place)
(eq place *place-1*))

(place-1-p *place-2*) --> nil
(place-1-p *place-1*) --> t

You can get a similar effect using lists, but you have to adopt a
convention where you, say, skip the first element to get at the actual
data. This relies on the two lists being distinct objects, but that
isn't true of empty lists---so you have to use non-empty ones.

(defvar *place-1* (list nil))
(defvar *place-2* (list nil))
(defun get-p1 ()
(cdr *place-1*))
(defun add-to-p1 (item)
(push item (cdr *place-1*)))

Then you can actually do the tests.

As Peter Seibel notes, though, there is most likely a better way to do
this. If you have user input that dictates which list to use, then you
can use that as the key to dispatch to the appropriate list, or use a
hash-table or an association list or some other data structure. That
would be a better and more Lispy solution.




--
Thomas A. Russ, USC/Information Sciences Institute
.



Relevant Pages

  • Re: The empty list and the end of a list
    ... takes a list (tree) as input and returns a list of all atoms. ... The embedded NIL differs from the ending NIL in its syntactic ... (atom (list tree)) ... NIL atoms, rather than flattening them as if they denoted empty lists, ...
    (comp.lang.lisp)
  • Re: my first Lisp code...comments welcome
    ... If you mean false, use nil (as if it were a variable holding false, ... nils here are both as empty lists, not as falses nor as symbols. ... > (declare (fixnum n)) ... > ans) ...
    (comp.lang.lisp)
  • Re: The empty list and the end of a list
    ... takes a list (tree) as input and returns a list of all atoms. ... The embedded NIL differs from the ending NIL in its syntactic ... NIL atoms, rather than flattening them as if they denoted empty lists, ... (atom (list tree)) ...
    (comp.lang.lisp)
  • Re: NIL is not of type CONS
    ... In Scheme, the empty list is ', not NIL. ... Many people around here know Scheme very well. ... The Scheme representation of lists and booleans introduces numerous ... a WIDGET class, you can pretend that there is a WIDGET* class which is ...
    (comp.lang.lisp)
  • Re: NIL is not of type CONS
    ... In lisp, 'means NIL. ... Common Lisp actually has a concept of uninitialized (unbound) variables, ... It's also the case that may not help you much, because you cannot distinguish between lists and booleans here. ...
    (comp.lang.lisp)