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

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

Re: Using setq to obtain a symbol from a list, so that I can assign a fu


From: Kevin Rodgers
Subject: Re: Using setq to obtain a symbol from a list, so that I can assign a function to it
Date: Mon, 19 May 2008 20:42:12 -0600
User-agent: Thunderbird 2.0.0.14 (Macintosh/20080421)

David Combs wrote:
In article <address@hidden>,
Kevin Rodgers  <address@hidden> wrote:
address@hidden wrote:
Oops... I got the subject wrong. Instead of

" Using setq to obtain a symbol from a list, so that I can assign a
function to it", it should read, "Using setq to assign value to the
result of a function". Sorry about that.
Use set instead of setq:

,----[ C-h f setq RET ]
| setq is a special form in `C source code'.
| (setq [sym val]...)
|
| Set each sym to the value of its val.
| The symbols sym are variables; they are literal (not evaluated).
| The values val are expressions; they are evaluated.
| Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
| The second val is not computed until after the first sym is set, and so on;
| each val can use the new value of variables set earlier in the `setq'.
| The return value of the `setq' form is the value of the last val.
|
| [back]
`----

,----[ C-h f set RET ]
| set is a built-in function in `C source code'.
| (set symbol newval)
|
| Set symbol's value to newval, and return newval.
|
| [back]
`----

Kevin, could you elaborate on that just a bit, on why
setq is *not* the right thing to use.

And, in general, when *do* you use plain set?

If I recall, the symbol whose value you want to set came from some data
structure, the list mentioned in the subject.  Since you don't know what
that symbol is ahead of time, you can't use setq: setq is a special form
that does not evaluate its SYMBOL argument, but sets that literal
SYMBOL.

On the other hand, set is a true function, meaning that all its
arguments are evaluated before the function itself is called.  So you
can write any expression that evaluates to a symbol as its first
argument.

Hope that helps,


--
Kevin Rodgers
Denver, Colorado, USA





reply via email to

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