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: Fri, 11 Nov 2011 07:45:59 -0800

> To add a further complication... If you wanted to pass a list of uids.

What do you want to test?  Whether the current `user-uid' is a member of that
list?  If so, use function `member' - do not use function `=' which tests
whether two numbers are equal.

> I tried a few possibilities.
>   (when (= 1000 1001 (user-uid)) 
>   (when (= (1000 1001) (user-uid)) 
>   (when ((= 1000 1001) (user-uid))

1. `C-h f RET user-uid' tells you that `user-uid' returns a number.

2. `C-h f =' tells you that `=' is a binary function: two (numeric) args.

3. `C-h f RET when' tells you that the first arg to `when' is a sexp that is
evaluated and its value tested as a boolean, and that there can be additional
args that are evaluated in order (if the first arg is true).

#2 tells you that your first try cannot be correct: it passes 3 args to `='.

#1 tells you that your second try cannot be correct: it passes a list, not a
number, to `='.

#3 passes `when' _only_ a test, no sexps to eval if the test is true.  And the
test is an invalid sexp (in Emacs Lisp): ((= X Y) Z).  That test sexp has no
valid function to pass arg Z to.  A function in Emacs Lisp is a symbol defined
as a function (e.g. (foo Z)) or it is a lambda expression (e.g. (lambda (arg)
(foo arg))).  But the function position of the sexp ((= X Y) Z) has only (= X
Y), which is neither (is not a valid function).

> As you can see, I'm just kind of shotgunning in the dark.

Yes.  It would help you to read the `Emacs Lisp Intro', available via `C-h i'.
It guides you in a reasonable, pedagogic order. 

> Looking at the section on lists in emacs-elisp-intro... doesn't really
> help.  Seems to get quite complicated right away and if I use the
> first basic example: '(rose violet daisy buttercup) Like this:
>   (when (= '(1000 1001) (user-uid)) 
> or even another example from emacs-lisp-intro
>  `'(this list has (a list inside of it))'
>   (when (= '(1000 (1001)) (user-uid)) 
> Well, those are wrong too.

Read the section again (and again).  Read first about evaluation.

(user-uid) is a sexp that is evaluated.  It returns a number, not a list.

There are no lists here, after arguments are evaluated.  The sexp (= ...) must
evaluate to a boolean value, not a non-empty list.  The sexp (user-uid) must
evaluate to a number, not a list.

What you're missing, besides some background on evaluation and lists, is that to
test membership in a list you use function `member', not function `='.




reply via email to

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