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

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

RE: how to load code conditional on uid


From: Drew Adams
Subject: RE: how to load code conditional on uid
Date: Sat, 12 Nov 2011 06:36:57 -0800

> C-h f member <RET> shows something that for a lightweight like me is
> your basic greek.
> 
> (member ELT LIST)
> Return non-nil if ELT is an element of LIST.  Comparison 
> done with `equal'.

(member ELT LIST) shows the calling sequence of function `member'.
ELT is the first parameter, LIST is the second.

See (Elisp manual) `Conventions' for documentation conventions.
Use `g' to go to a section of the manual such as `Conventions'.

> The value is actually the tail of LIST whose car is ELT.

This completes the description of the function signature: its parameters are ELT
and LIST, and its return value is the (longest) tail of LIST whose first element
is ELT.  That is, it returns nil if element ELT is not a member of LIST, and if
it is a member then it returns a sublist (a tail) whose first element is ELT.

> Doing an index search in `emacs-lisp-intro' on `member' shows 
> no hits so apparently it is not used or explained in that document.

It is an pedagogical intro, similar to a tutorial.  The reference manual for
Emacs Lisp is the Elisp manual.  There, `i member' gives you more info about the
function.

> Not sure how I would find out what ELT means.

Read the doc conventions section mentioned above.

> Elisp manaual on ELT shows: Function: elt sequence index

That's a function named `elt'.  It has nothing to do with the `member'
function's parameter referred to as ELT in its calling-sequence description.

But if you looked up `member' in the Elisp manual you would find this:

Function: member object list
 The function `member' tests to see whether OBJECT is a member of
 LIST, comparing members with OBJECT using `equal'.  If OBJECT is a
 member, `member' returns a list starting with its first occurrence
 in LIST.  Otherwise, it returns `nil'.
...

ELT and OBJECT are just names - ways to refer to the first parameter.

> But at a glance it sounds as if it could be a uid like 1000 or maybe
> (user-uid).
> (when (member 1000 (1000 1001 1002))...

You correctly understood that the first parameter is tested to see if it is an
element of the second parameter (a list).  The only thing you didn't get was
that `member', as an ordinary function, evaluates its arguments, so if you want
to pass it the constant list (1000 1001 1002) then you need to quote that sexp:

 (when (member 1000 '(1000 1001 1002))... 

Otherwise, Lisp tries to evaluate the sexp (1000 1001 1002).  In doing that, it
expects the first element, 1000, to be a _function_ and tries to apply that
function to the other elements - error.

If you add the quote mark then the sexp to be evaluated is (quote (1000 1001
1002)), which evaluates to the list (1000 1001 1002).

> or maybe (when (member (user-uid) (1000 1001 1002)) 

Again, correct, except for the missing quote mark.

You just need to spend a little more time reading the Lisp intro and then some
of the Elisp manual.  IOW, do a little more homework.  This too will help:

http://www.emacswiki.org/emacs/LearnEmacsLisp




reply via email to

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