From ... Path: archiver1.google.com!news2.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!news2.kpn.net!news.kpn.net!nslave.kpnqwest.net!nloc.kpnqwest.net!nmaster.kpnqwest.net!nreader1.kpnqwest.net.POSTED!not-for-mail Newsgroups: comp.lang.lisp Subject: Re: setq setf References: Mail-Copies-To: never From: Erik Naggum Message-ID: <3224632704949565@naggum.net> Organization: Naggum Software, Oslo, Norway Lines: 32 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sat, 09 Mar 2002 03:18:18 GMT X-Complaints-To: newsmaster@KPNQwest.no X-Trace: nreader1.kpnqwest.net 1015643898 193.71.199.50 (Sat, 09 Mar 2002 04:18:18 MET) NNTP-Posting-Date: Sat, 09 Mar 2002 04:18:18 MET Xref: archiver1.google.com comp.lang.lisp:28234 * Cristina | 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.