Subject: Re: setq setf
From: Erik Naggum <erik@naggum.net>
Date: Sat, 09 Mar 2002 03:18:18 GMT
Newsgroups: comp.lang.lisp
Message-ID: <3224632704949565@naggum.net>

* Cristina <ZZYTNTOWPPOD@spammotel.com>
| I'm new to Lisp, can anyone tell me what's the difference between 
| "setq" and "setf", from what I understood setq assigns a value to a 
| symbol, while setf changes the value of the place. But from what I see 
| in examples, it appears to me that in place of "setf", I can use "setq" 
| equivalently or vice versa. 

  You can always use setf where setq is applicable, so if you always use
  setf, you cannot go wrong.  setq only works on variables that are named
  by symbols.

  Moreover, (setq foo bar), where foo is a special binding acts precisely
  like (setf (symbol-value 'foo) bar), but symbol-value cannot reach
  lexical bindings.  Historically, we have (set 'foo bar) equivalent to
  (setf (symbol-value 'foo) bar), too, but although set is available in the
  language, it is deprecated.  [I think it is somehwat unfortunate that the
  words set and get are both used up by the language for features that are
  no longer as popular as the length and simplicity of the names indicate.]
  setq derives its name from the preponderance of (set (quote ...) ...),
  but setq has been given the role of a lexical setter, not just the symbol
  setter role of the historical set with quote.

  Some think that code looks more modern with setf than with setq and that
  there is no need for setq, anymore, either, which paves the way for a new
  definition of set in some future standard or language development.  So in
  the meantime, just reagard setf as the general setter and setq as a
  setter for the special, but not uncommon, case of setting a variable.
  
///
-- 
  In a fight against something, the fight has value, victory has none.
  In a fight for something, the fight is a loss, victory merely relief.