From: TomL
Subject: defvar / defconstant
Date: 
Message-ID: <1133720775.446758.241690@o13g2000cwo.googlegroups.com>
Hello,

I just began to learn Common Lisp, and as you can imagine I've got some
questions. What is the difference between defvar and defconstant ?

Both defines a name/value that cannot be changed... Am I wrong ?

Thanks a lot for your help (and sorry for this stupid (I guess)
question).

From: Paul F. Dietz
Subject: Re: defvar / defconstant
Date: 
Message-ID: <p6SdnaX1boFAqg7e4p2dnA@dls.net>
TomL wrote:
> Hello,
> 
> I just began to learn Common Lisp, and as you can imagine I've got some
> questions. What is the difference between defvar and defconstant ?
> 
> Both defines a name/value that cannot be changed... Am I wrong ?

No, the value of the DEFVAR-ed symbol may be changed (either by
setting or binding it).

	Paul
From: TomL
Subject: Re: defvar / defconstant
Date: 
Message-ID: <1133722127.903857.33420@f14g2000cwb.googlegroups.com>
Thanks for your answer.

Correct me if I'm wrong:

- A symbol defined by DEFVAR can be changed, by a SETQ for instance,
but cannot be changed by another DEFVAR.
- A symbol defined by DEFCONSTANT cannot be changed by any method.

Is that right ?
From: Rainer Joswig
Subject: Re: defvar / defconstant
Date: 
Message-ID: <joswig-2F9E18.20094504122005@news-europe.giganews.com>
In article <·······················@f14g2000cwb.googlegroups.com>,
 "TomL" <········@vtek.chalmers.se> wrote:

> Thanks for your answer.
> 
> Correct me if I'm wrong:
> 
> - A symbol defined by DEFVAR can be changed, by a SETQ for instance,
> but cannot be changed by another DEFVAR.
> - A symbol defined by DEFCONSTANT cannot be changed by any method.
> 
> Is that right ?

That's basically right. See also DEFPARAMETER .
From: Wade Humeniuk
Subject: Re: defvar / defconstant
Date: 
Message-ID: <joHkf.139991$S4.83381@edtnps84>
TomL wrote:
> Hello,
> 
> I just began to learn Common Lisp, and as you can imagine I've got some
> questions. What is the difference between defvar and defconstant ?
> 
> Both defines a name/value that cannot be changed... Am I wrong ?
> 

Kind of,  the REPL is your friend, when in doubt try a little
experiment (find a compliant CL).

CL-USER 1 > (defconstant x 1)
X

CL-USER 2 > x
1

CL-USER 3 > (defun xval () x)
XVAL

CL-USER 4 > (xval)
1

CL-USER 5 > (defconstant x 2)
X

CL-USER 6 > x
2

CL-USER 7 > (xval)
2

CL-USER 8 > (compile 'xval)
XVAL
NIL
NIL

CL-USER 9 > (defconstant x 3)
X

CL-USER 10 > (xval)
2

CL-USER 11 > x
3

CL-USER 12 > (macroexpand '(defconstant x 2))
(COMPILER-LET ((DSPEC::*LOCATION* (QUOTE (:INSIDE (DEFCONSTANT X) :LISTENER)))) 
(COMPILER::TOP-LEVEL-FORM-NAME (DEFCONSTANT X) (EVAL-WHEN (:COMPILE-TOPLEVEL) 
(COMPILER::ADD-CONSTANT (QUOTE X) 2 NIL)) (DSPEC:INSTALL-DEFCONSTANT (QUOTE X) 
(DSPEC:LOCATION) 2)))
T

CL-USER 13 > (defvar y 1)
Y

CL-USER 14 > (defun yval () y)
YVAL

CL-USER 15 > (compile 'yval)
YVAL
NIL
NIL

CL-USER 16 > y
1

CL-USER 17 > (setf y 2)
2

CL-USER 18 > y
2

CL-USER 19 > (yval)
2

CL-USER 20 >