From: Jedrzej Nasiadek
Subject: [Q] setf
Date: 
Message-ID: <3afb2579@news.astercity.net>
Hi,

 I'm just beginning my journey with lisp, and I wonder
what is the difference between
  (setq a-variable '(something and stuff))
and
  (setf a-variable '(something and stuff))

I mean exactly in statements as above, I know that setq can assing a value
to a _single_ variable and setf changes the value of given place in the
memory. But in some pieces of code I see, that people use setf JUST to
assign a value to a variable.
Is there any pros of using setf in clauses like above?

cheers,
   -J

From: Kent M Pitman
Subject: Re: [Q] setf
Date: 
Message-ID: <sfwbsp08yqz.fsf@world.std.com>
Jedrzej Nasiadek <···@yenisko.home.astercity.net> writes:

>  I'm just beginning my journey with lisp, and I wonder
> what is the difference between
>   (setq a-variable '(something and stuff))
> and
>   (setf a-variable '(something and stuff))

No difference. SETF expands to SETQ if the variable is a normal variable.
SETQ expands to SETF if the "variable" is a symbol-macro.

The argument to SETQ can only be a symbol.

The argument to SETF can be any "place" form.  Symbols are a kind of 
place form.

Some people use only SETF, and this works.

Some of us, out of tradition, mostly, use SETQ for variables and SETF for
non-variables [i.e., for more complicated "places"].

> I mean exactly in statements as above, I know that setq can assing a value
> to a _single_ variable and setf changes the value of given place in the
> memory. But in some pieces of code I see, that people use setf JUST to
> assign a value to a variable.
> Is there any pros of using setf in clauses like above?

The issue is purely personal taste in the example you offer.
From: Paolo Amoroso
Subject: Re: [Q] setf
Date: 
Message-ID: <k6=7OgQrPlcoSfvOF6HDtZjFXVl5@4ax.com>
On 11 May 2001 01:34:17 +0100, Jedrzej Nasiadek
<···@yenisko.home.astercity.net> wrote:

> I mean exactly in statements as above, I know that setq can assing a value
> to a _single_ variable and setf changes the value of given place in the

You can actually use SETQ with more than one variable:

(setq var1  val1
      var2  val2
      ;; ...
      var-n val2)


Paolo
-- 
EncyCMUCLopedia * Extensive collection of CMU Common Lisp documentation
http://cvs2.cons.org:8000/cmucl/doc/EncyCMUCLopedia/