Re: possibly silly question re quoting of function arguments...
- From: tar@xxxxxxxxxxxxx (Thomas A. Russ)
- Date: 28 Apr 2006 12:22:35 -0700
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
.
- Follow-Ups:
- Re: possibly silly question re quoting of function arguments...
- From: Takehiko Abe
- Re: possibly silly question re quoting of function arguments...
- References:
- possibly silly question re quoting of function arguments...
- From: birlinn@xxxxxxxxx
- Re: possibly silly question re quoting of function arguments...
- From: Peter Seibel
- Re: possibly silly question re quoting of function arguments...
- From: birlinn@xxxxxxxxx
- Re: possibly silly question re quoting of function arguments...
- From: Peter Seibel
- Re: possibly silly question re quoting of function arguments...
- From: Takehiko Abe
- possibly silly question re quoting of function arguments...
- Prev by Date: Re: which one should I choose?
- Next by Date: Re: Beautiful code
- Previous by thread: Re: possibly silly question re quoting of function arguments...
- Next by thread: Re: possibly silly question re quoting of function arguments...
- Index(es):
Relevant Pages
|
|