all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kevin Rodgers <kevin.d.rodgers@gmail.com>
To: help-gnu-emacs@gnu.org
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	[thread overview]
Message-ID: <g0tdpt$vc4$1@ger.gmane.org> (raw)
In-Reply-To: <g0nlbe$13h$1@reader2.panix.com>

David Combs wrote:
> In article <mailman.10729.1208927476.18990.help-gnu-emacs@gnu.org>,
> Kevin Rodgers  <kevin.d.rodgers@gmail.com> wrote:
>> srinik001@hotmail.com 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	other threads:[~2008-05-20  2:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-22  2:28 Using setq to obtain a symbol from a list, so that I can assign a function to it srinik001
2008-04-22  5:19 ` srinik001
2008-04-22 12:54   ` Barry Margolin
2008-04-23  4:40     ` srinik001
2008-04-23 22:14       ` Pascal Bourguignon
2008-04-24  2:50       ` Barry Margolin
2008-04-28  1:03         ` srinik001
2008-04-23  5:10   ` Kevin Rodgers
     [not found]   ` <mailman.10729.1208927476.18990.help-gnu-emacs@gnu.org>
2008-05-17 22:14     ` David Combs
2008-05-20  2:42       ` Kevin Rodgers [this message]
2008-04-22 15:22 ` Ted Zlatanov
2008-04-22 18:36   ` Pascal Bourguignon
2008-05-17 22:20     ` David Combs
2008-04-22 19:59 ` Pascal Bourguignon
2008-04-23  3:11   ` Timothy Hobbs
     [not found]   ` <mailman.10727.1208920326.18990.help-gnu-emacs@gnu.org>
2008-04-23  4:06     ` Barry Margolin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='g0tdpt$vc4$1@ger.gmane.org' \
    --to=kevin.d.rodgers@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.