From: Albert Reiner
Subject: defconstant name of structure
Date: 
Message-ID: <vw8mzw7pw99.fsf@berry.phys.ntnu.no>
Can I portably make a symbol's value constant with defconstant, and
still use that same symbol as the name of a structure?

I would guess so as defstructure should only care about the name, not
about the value of the symbol that is used; also, CMUCL seems to
accept this without problems:

,----
| CL-USER> (defconstant +foo+ 5)
| +FOO+
| CL-USER> (defstruct +foo+ (x))
| +FOO+
`----

This is really two questions:

- Is this standards conforming, as I suppose it is?

- How do I arrive at that conclusion from the standard?  CLHS exegesis
  is not always entirely obvious to me (will it ever be?); currently
  my best guess is that this follows from the identification of
  structure-name as a symbol in the defstruct specification.

Regards,

Albert.

From: Thomas A. Russ
Subject: Re: defconstant name of structure
Date: 
Message-ID: <ymizn07481o.fsf@sevak.isi.edu>
Albert Reiner <·······@tph.tuwien.ac.at> writes:

> 
> Can I portably make a symbol's value constant with defconstant, and
> still use that same symbol as the name of a structure?

Yes.  The value of a symbol is distinct from its function value and its
use as a structure or class name.

> ,----
> | CL-USER> (defconstant +foo+ 5)
> | +FOO+
> | CL-USER> (defstruct +foo+ (x))
> | +FOO+
> `----
> 
> This is really two questions:
> 
> - Is this standards conforming, as I suppose it is?

Yes, it is.

> - How do I arrive at that conclusion from the standard?  CLHS exegesis
>   is not always entirely obvious to me (will it ever be?); currently
>   my best guess is that this follows from the identification of
>   structure-name as a symbol in the defstruct specification.

A harder question to answer.  Especially since structures and classes
would have to have different names.  But that is because both of them
introduce the names of TYPES to Common Lisp.

In the case in question, the only restriction that DEFCONSTANT
introduces is that you are not allowed to change the SYMBOL-VALUE of the
constant.  Off the top of my head, though, I can't recall whether you
are allowed to use a local lexical variable with the same name as a
global constant.  (See I said it was hard to answer :)

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Peter Seibel
Subject: Re: defconstant name of structure
Date: 
Message-ID: <m3r7ljjgdw.fsf@javamonkey.com>
···@sevak.isi.edu (Thomas A. Russ) writes:

> In the case in question, the only restriction that DEFCONSTANT
> introduces is that you are not allowed to change the SYMBOL-VALUE of
> the constant. Off the top of my head, though, I can't recall whether
> you are allowed to use a local lexical variable with the same name
> as a global constant. (See I said it was hard to answer :)

Nope. From the DEFCONSTANT dictionary entry:

  The consequences are undefined when constant symbols are rebound as
  either lexical or dynamic variables. In other words, a reference to
  a symbol declared with defconstant always refers to its global
  value.

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: Albert Reiner
Subject: Re: defconstant name of structure
Date: 
Message-ID: <vw8zn06pe8v.fsf@berry.phys.ntnu.no>
Thanks to all who clarified this for me.  But...

[Peter Seibel <·····@javamonkey.com>, Wed, 22 Dec 2004 01:00:59 GMT]:
> Nope. From the DEFCONSTANT dictionary entry:
> 
>   The consequences are undefined when constant symbols are rebound as
>   either lexical or dynamic variables. In other words, a reference to
>   a symbol declared with defconstant always refers to its global
>   value.

This is another point that I don't quite understand: "In other words"
seems to imply that both sentences state the same in different ways,
but what exactly is so "undefined" about rebinding a constant symbol
if that always refers to the global value?

Albert.
From: Gareth McCaughan
Subject: Re: defconstant name of structure
Date: 
Message-ID: <873bxyl4lh.fsf@g.mccaughan.ntlworld.com>
Albert Reiner <·······@tph.tuwien.ac.at> writes:

> Thanks to all who clarified this for me.  But...
> 
> [Peter Seibel <·····@javamonkey.com>, Wed, 22 Dec 2004 01:00:59 GMT]:
> > Nope. From the DEFCONSTANT dictionary entry:
> > 
> >   The consequences are undefined when constant symbols are rebound as
> >   either lexical or dynamic variables. In other words, a reference to
> >   a symbol declared with defconstant always refers to its global
> >   value.
> 
> This is another point that I don't quite understand: "In other words"
> seems to imply that both sentences state the same in different ways,
> but what exactly is so "undefined" about rebinding a constant symbol
> if that always refers to the global value?

I think it means: (1) the consequences are undefined if you
do this, therefore (2) no conforming program does it, therefore
(3) in a conforming program there will be no attempts to rebind
constant symbols, therefore (4) in a conforming program you
can safely assume that wherever you see a constant symbol it
refers to its global value.

-- 
Gareth McCaughan
.sig under construc
From: Albert Reiner
Subject: Re: defconstant name of structure
Date: 
Message-ID: <vw8pt12pc11.fsf@berry.phys.ntnu.no>
[Gareth McCaughan <················@pobox.com>, Wed, 22 Dec 2004 15:48:46 GMT]:
> I think it means: (1) the consequences are undefined if you
> do this, therefore (2) no conforming program does it, therefore
> (3) in a conforming program there will be no attempts to rebind
> constant symbols, therefore (4) in a conforming program you
> can safely assume that wherever you see a constant symbol it
> refers to its global value.

Ah, I see.  Makes sense, in a way.

Thanks,

Albert.
From: Pascal Bourguignon
Subject: Re: defconstant name of structure
Date: 
Message-ID: <874qifk8ps.fsf@thalassa.informatimago.com>
Albert Reiner <·······@tph.tuwien.ac.at> writes:

> Can I portably make a symbol's value constant with defconstant, and
> still use that same symbol as the name of a structure?
> 
> I would guess so as defstructure should only care about the name, not
> about the value of the symbol that is used; also, CMUCL seems to
> accept this without problems:
> 
> ,----
> | CL-USER> (defconstant +foo+ 5)
> | +FOO+
> | CL-USER> (defstruct +foo+ (x))
> | +FOO+
> `----
> 
> This is really two questions:
> 
> - Is this standards conforming, as I suppose it is?

That's my understanding too.

 
> - How do I arrive at that conclusion from the standard?  CLHS exegesis
>   is not always entirely obvious to me (will it ever be?); currently
>   my best guess is that this follows from the identification of
>   structure-name as a symbol in the defstruct specification.

What is forbidden to do on a symbol declared a constant with
defconstant is not done by defstruct.  So they're compatible.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

There is no worse tyranny than to force a man to pay for what he does not
want merely because you think it would be good for him. -- Robert Heinlein