Why does this work...
(member 'a '(a b c))
(A B C)
... but not this?
(member '"A" '("A" "B" "C"))
NIL
Should I be using read-from-string when I construct my list?
Thanks,
JT
Jack Tanner <····@hotmail.com> writes:
> Why does this work...
>
> (member 'a '(a b c))
> (A B C)
>
> ... but not this?
>
> (member '"A" '("A" "B" "C"))
> NIL
>
> Should I be using read-from-string when I construct my list?
In the latter case, you probably mean something like:
(member '"A" '("A" "B" "C") :test #'string=)
You want to check up on what the default equality test for member is
and how it interacts with strings.
--
Howard Ding
<······@hading.dnsalias.com>
Also, you don't need to quote (that is, single quote) "A". What you
should have is :
(member "A" '("A" "B" "C") :test #'string=)
Lowell
Howard Ding wrote:
> Jack Tanner <····@hotmail.com> writes:
>
>
>>Why does this work...
>>
>>(member 'a '(a b c))
>>(A B C)
>>
>>... but not this?
>>
>>(member '"A" '("A" "B" "C"))
>>NIL
>>
>>Should I be using read-from-string when I construct my list?
>
>
> In the latter case, you probably mean something like:
>
> (member '"A" '("A" "B" "C") :test #'string=)
>
> You want to check up on what the default equality test for member is
> and how it interacts with strings.
>
Jack Tanner wrote:
> Why does this work...
>
> (member 'a '(a b c))
> (A B C)
>
> ... but not this?
>
> (member '"A" '("A" "B" "C"))
> NIL
It is a RTFM question. :) MEMBER uses #'EQL as a test function by default.
Now
cl-prompt> (eql "foo" "foo")
NIL
However
cl-prompt> (string= "foo" "foo")
T
Therefore
cl-prompt> (member "A" '("A" "B" "C") :test #'string=)
("A" "B" "C")
Your orignal call using symbols is really
cl-prompt> (member 'A '(A B C) :test #'eql) ; Where the :TEST argument
; is defaulted.
>
> Should I be using read-from-string when I construct my list?
Only if you need to.
Cheers
--
Marco