From: Ruhi Bloodworth
Subject: Confused by special variables
Date: 
Message-ID: <slrnaisujn.1m2.ruhi@colophon.cjb.net>
Hi,
I'm a schemer who is trying out common lisp for the first time (using
OpenMCL) . I don't understand why I get a warining when changing a
top-level lexecal variable in the following example

? (setq regular 5)
5
? (defun change-regular ()
  (setq regular 6))
;Compiler warnings:
;   Undeclared free variable REGULAR, in CHANGE-REGULAR.
CHANGE-REGULAR

? (defvar *special* 5)
*SPECIAL
?(defun change-special ()
 (setq *special* 6))
CHANGE-SPECIAL

As far as I know the only difference between special and lexecal
variables is the environment in which they are looked up.
Special variables are looked up in the environment present when their
enclosing function is applied and lexical variables are looked up in the
environment present when their enclosing environment is defined.

What am I missing?

Regards,
Ruhi Bloodworth
 

From: Kalle Olavi Niemitalo
Subject: Re: Confused by special variables
Date: 
Message-ID: <87y9chbdp2.fsf@Astalo.y2000.kon.iki.fi>
Ruhi Bloodworth <····@colophon.cjb.net> writes:

> I'm a schemer who is trying out common lisp for the first time (using
> OpenMCL) . I don't understand why I get a warining when changing a
> top-level lexecal variable in the following example

Common Lisp does not support top-level lexical variables.
See CLHS section 3.1.1, Introduction to Environments.
Use special variables instead.
From: Duane Rettig
Subject: Re: Confused by special variables
Date: 
Message-ID: <41ya9m4p8.fsf@beta.franz.com>
Kalle Olavi Niemitalo <···@iki.fi> writes:

> Ruhi Bloodworth <····@colophon.cjb.net> writes:
> 
> > I'm a schemer who is trying out common lisp for the first time (using
> > OpenMCL) . I don't understand why I get a warining when changing a
> > top-level lexecal variable in the following example
> 
> Common Lisp does not support top-level lexical variables.
> See CLHS section 3.1.1, Introduction to Environments.

Correct.

> Use special variables instead.

I suggest rather using lexical variables at non-top-level:

(let ((regular 5))

  (defun change-regular ()
    (setq regular 6))

  ;; [ other code to access/set regular ... ]

  )

-- 
Duane Rettig          Franz Inc.            http://www.franz.com/ (www)
1995 University Ave Suite 275  Berkeley, CA 94704
Phone: (510) 548-3600; FAX: (510) 548-8253   ·····@Franz.COM (internet)
From: Ruhi Bloodworth
Subject: Re: Confused by special variables
Date: 
Message-ID: <slrnaittqp.255.ruhi@colophon.cjb.net>
I want to thank everyone for their replays. I read CLHS 3.1.1.X without
ever realizing that there were no top-level lexical variables.  

I guess I will have take things more slowly and read Common Lisp the
Language.

Thanks again,
Ruhi Bloodworth
From: Marcin Tustin
Subject: Re: Confused by special variables
Date: 
Message-ID: <yztb65zje99k.fsf@werewolf.i-did-not-set--mail-host-address--so-shoot-me>
Ruhi Bloodworth <····@colophon.cjb.net> writes:

> I want to thank everyone for their replays. I read CLHS 3.1.1.X without
> ever realizing that there were no top-level lexical variables.  
> 
> I guess I will have take things more slowly and read Common Lisp the
> Language.

    I recommend you do not do this. I recommend that you read the ANSI
standard, or, equivalently, but more cheaply and more satisfactorily,
the HyperSpec.

--
Screw you, hippy.
From: Joe Marshall
Subject: Re: Confused by special variables
Date: 
Message-ID: <2GEX8.13376$uw.7294@rwcrnsc51.ops.asp.att.net>
"Ruhi Bloodworth" <····@colophon.cjb.net> wrote in message ························@colophon.cjb.net...
>
> As far as I know the only difference between special and lexecal
> variables is the environment in which they are looked up.

Careful, here, you are exposing your Scheme background!

A special variable is *not* looked up in an environment.  The value
of a special variable is named by a symbol and the value is in
the value cell of the symbol.
From: Joel Ray Holveck
Subject: Re: Confused by special variables
Date: 
Message-ID: <y7c4rf4bibo.fsf@sindri.juniper.net>
>> As far as I know the only difference between special and lexecal
>> variables is the environment in which they are looked up.
> Careful, here, you are exposing your Scheme background!
> A special variable is *not* looked up in an environment.  The value
> of a special variable is named by a symbol and the value is in
> the value cell of the symbol.

My understanding is that a special variable is looked up in the
current dynamic environment.  It is still true that the "value cell"
(which may be an abstract construct) of a symbol holds its value in
the current dynamic environment.  However, the concept of multiple
dynamic environments may be useful in a Lisp that supports stack
groups, such as for multithreading.

Cheers,
joelh
From: Joe Marshall
Subject: Re: Confused by special variables
Date: 
Message-ID: <XKRX8.22137$uw.14158@rwcrnsc51.ops.asp.att.net>
"Joel Ray Holveck" <·····@juniper.net> wrote in message ····················@sindri.juniper.net...
> >> As far as I know the only difference between special and lexecal
> >> variables is the environment in which they are looked up.
> > Careful, here, you are exposing your Scheme background!
> > A special variable is *not* looked up in an environment.  The value
> > of a special variable is named by a symbol and the value is in
> > the value cell of the symbol.
>
> My understanding is that a special variable is looked up in the
> current dynamic environment.  It is still true that the "value cell"
> (which may be an abstract construct) of a symbol holds its value in
> the current dynamic environment.  However, the concept of multiple
> dynamic environments may be useful in a Lisp that supports stack
> groups, such as for multithreading.

You are correct.