[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
Re: Using setq to obtain a symbol from a list, so that I can assign a function to it
Mon, 19 May 2008 20:42:12 -0600
Thunderbird 22.214.171.124 (Macintosh/20080421)
David Combs wrote:
In article <address@hidden>,
Kevin Rodgers <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
| 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.
,----[ 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.
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
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
Hope that helps,
Denver, Colorado, USA