From: David Bakhash
Subject: defconstant
Date: 
Message-ID: <m3itk9t8x8.fsf@alum.mit.edu>
Hi,

I'm writing to find out about defconstant.  If I write:

(defconstant +const+ (list 1 2 3))

then my current understanding is that I'm under a contract that while
the program is running, I won't do something like:

(setq +const+ "hello")

But what about

(setf (first +const+ "hello")) ???

From the HS:

  If a defconstant form appears as a top level form, the compiler must
  recognize that name names a constant variable. An implementation may
  choose to evaluate the value-form at compile time, load time, or
  both. Therefore, users must ensure that the initial-value can be
  evaluated at compile time (regardless of whether or not references
  to name appear in the file) and that it always evaluates to the same
  value.                                                          ^^^^

But the ``same'' under what operation?  My guess is that it's #'EQ.

thanks,
dave

From: Barry Margolin
Subject: Re: defconstant
Date: 
Message-ID: <RPHB6.427$U4.18202@burlma1-snr2>
In article <··············@alum.mit.edu>,
David Bakhash  <·····@alum.mit.edu> wrote:
>Hi,
>
>I'm writing to find out about defconstant.  If I write:
>
>(defconstant +const+ (list 1 2 3))
>
>then my current understanding is that I'm under a contract that while
>the program is running, I won't do something like:
>
>(setq +const+ "hello")
>
>But what about
>
>(setf (first +const+ "hello")) ???
>
>From the HS:
>
>  If a defconstant form appears as a top level form, the compiler must
>  recognize that name names a constant variable. An implementation may
>  choose to evaluate the value-form at compile time, load time, or
>  both. Therefore, users must ensure that the initial-value can be
>  evaluated at compile time (regardless of whether or not references
>  to name appear in the file) and that it always evaluates to the same
>  value.                                                          ^^^^
>
>But the ``same'' under what operation?  My guess is that it's #'EQ.

See section 3.2.2.3, Semantic Constraints:

      Constant variables defined in the compilation environment must have a
      similar value at run time. A reference to a constant variable in
      source code is equivalent to a reference to a literal object that is
      the value of the constant variable.

This prohibits you from modifying any of the constituents of the value,
which then licenses the compiler to inline-expand references to constants,
e.g.

(car +const+)

may be transformed by the compiler into:

(car (list 1 2 3))

or (more likely):

(car '(1 2 3))

which it may then constant-fold into:

1

-- 
Barry Margolin, ······@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: David Bakhash
Subject: Re: defconstant
Date: 
Message-ID: <m3puedpdat.fsf@alum.mit.edu>
>>>>> "barry" == Barry Margolin <······@genuity.net> writes:

 barry> This prohibits you from modifying any of the constituents of
 barry> the value, which then licenses the compiler to inline-expand
 barry> references to constants

thanks.  useful info.  definitely the answer I was looking for.

dave