help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: member returns list (was: Re: To `boundp' or not to `boundp'?)


From: Emanuel Berg
Subject: Re: member returns list (was: Re: To `boundp' or not to `boundp'?)
Date: Wed, 02 Sep 2015 23:20:48 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Drew Adams <drew.adams@oracle.com> writes:

>> The `car' example I provided may look cool (?) but
>> it isn't anything that cannot be done with
>> "memberp", because obviously the car is known,
>> otherwise one wouldn't be able to search for it.
>
> Sure, if you just want the element you're testing
> for, then (car (member 'foo xs)) is no better than
> (and (memberp 'foo xs) 'foo)
>
> (In the second example, if the element needs to be
> computed, let-bind it to avoid computing it twice.)

Agreed: the first example is better unless you do
that. Better style, and sometimes even better
performance tho in most cases equal or a negligeable
difference. However, as the trained eye does, it
automagically associates beauty with speed and power :)

> But maybe you want the next element after `foo':
> (cadr (member 'foo xs))

I tried to visualize such use but as for me I am still
unable, probably because I would instead do something
else that is practically equivalent in that situation.

> You get the idea. Often, if you care about the list
> structure it is because you are modifying it
> (destructive operations). (Not always - e.g., (cadr
> (member 'foo xs)).)
>
> And yes, most other uses of `member' (and `memq')
> are just tests for membership. You can see this by
> grepping the Emacs Lisp sources.

Most definitely a good method in cases such as this
and many others. If I find any Elisp-kung-fu-ish use
of `member', I'll post it here faster than a Bruce Lee
finger jab.

-- 
underground experts united
http://user.it.uu.se/~embe8573




reply via email to

[Prev in Thread] Current Thread [Next in Thread]