[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

gengyangcai

12/1/2015 6:57:00 PM

What does this piece of code mean ? Looks weird to me ...

> (member '(a) '((a) (z)) :test #'equal)
((A) (Z))
7 Answers

Jim Ottaway

12/1/2015 8:46:00 PM

0

>>>>> CAI GENGYANG <gengyangcai@gmail.com> writes:
> What does this piece of code mean ? Looks weird to me ...
>> (member '(a) '((a) (z)) :test #'equal)
> ((A) (Z))

The first line looks to see if '(a) is a member of the list '((a) (z))
using the function equal as the test (the #' prefix means something like
"the function equal").

I find it tricky to describe succintly what "equal" means in this case,
but I think the hyperspec page on it is quite understandable:
http://www.lispworks.com/documentation/HyperSpec/Body/f_equal...

The second line is what the function member returns if there's a match:
a list with the matched item first followed by any remainder of the list
that follows it.


Yours sincerely,
--
Jim Ottaway

gengyangcai

12/1/2015 9:12:00 PM

0

This is the description given in Paul Graham's Ansi Common Lisp :

One of the keyword arguments accepted by member is a : t e s t argument.
If you pass some function as the : t e s t argument in a call to member, then that function will be used to test for equality instead of eql. So if we want to find a member of a list that is equal to a given object, we might say:

> (member '(a) '((a) (z)) :test #'equal) ((A) (Z))


On Wednesday, December 2, 2015 at 4:46:22 AM UTC+8, Jim Ottaway wrote:
> >>>>> CAI GENGYANG <gengyangcai@gmail.com> writes:
> > What does this piece of code mean ? Looks weird to me ...
> >> (member '(a) '((a) (z)) :test #'equal)
> > ((A) (Z))
>
> The first line looks to see if '(a) is a member of the list '((a) (z))
> using the function equal as the test (the #' prefix means something like
> "the function equal").
>
> I find it tricky to describe succintly what "equal" means in this case,
> but I think the hyperspec page on it is quite understandable:
> http://www.lispworks.com/documentation/HyperSpec/Body/f_equal...
>
> The second line is what the function member returns if there's a match:
> a list with the matched item first followed by any remainder of the list
> that follows it.
>
>
> Yours sincerely,
> --
> Jim Ottaway

Pascal J. Bourguignon

12/1/2015 9:40:00 PM

0

CAI GENGYANG <gengyangcai@gmail.com> writes:

> This is the description given in Paul Graham's Ansi Common Lisp :
>
> One of the keyword arguments accepted by member is a : t e s t argument.
> If you pass some function as the : t e s t argument in a call to
> member, then that function will be used to test for equality instead
> of eql. So if we want to find a member of a list that is equal to a
> given object, we might say:
>
>> (member '(a) '((a) (z)) :test #'equal) ((A) (Z))

Why do you do that? We know what the test argument is for, and what the
member function does. Any lisp newbie knows it, since it's a typical
newbie exercise to implement this function.

There's no point in copying here sections of books.


Read them and understand them by yourself!


--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Stefan Monnier

12/1/2015 9:45:00 PM

0

> What does this piece of code mean ? Looks weird to me ...

That's because it is weird.

>> (member '(a) '((a) (z)) :test #'equal)

This says in a round-about way that for (a) and ((a) (z)) the member
test is *not* equal (note the # sign used for "inequality").


Stefan

Pascal J. Bourguignon

12/1/2015 9:52:00 PM

0

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> What does this piece of code mean ? Looks weird to me ...
>
> That's because it is weird.
>
>>> (member '(a) '((a) (z)) :test #'equal)
>
> This says in a round-about way that for (a) and ((a) (z)) the member
> test is *not* equal (note the # sign used for "inequality").

:-)

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Jim Ottaway

12/1/2015 10:44:00 PM

0

>>>>> Stefan Monnier <monnier@iro.umontreal.ca> writes:
> This says in a round-about way that for (a) and ((a) (z)) the member
> test is *not* equal (note the # sign used for "inequality").

This doesn't look right to me (the # sign = inequality thing) but
perhaps I am missing something?

Yours sincerely,
--
Jim Ottaway

Jim Ottaway

12/2/2015 12:33:00 AM

0

>>>>> Jim Ottaway <jeho@jeho.org> writes:
> This doesn't look right to me (the # sign = inequality thing) but
> perhaps I am missing something?

OK, I've had a look at some other posts here and I think I see it now.

Yours sincerely,
--
Jim Ottaway