From: Stefan Monnier
Subject: defconstant
Date: 
Message-ID: <4aptsr$j2b@info.epfl.ch>
Is it possible to use defconstant to define anything else than
trivial values ?

A file such as:

        (defstruct s a)
        (defconstant toto (make-s :a 1))
        
is refused by AllegroCL:

        USER(26): :cl ~/tmp/toto.lisp
        ; --- Compiling file /users/monnier/tmp/toto.lisp ---
        ; Compiling MAKE-S
        ; While compiling (:TOP-LEVEL-FORM "toto.lisp" 2):
        Error: attempt to call `MAKE-S' which is an undefined function.
          [condition type: UNDEFINED-FUNCTION]

I can work around this by defining toto as a defvar initialized to nil and then
set it to some (constant) value inside an init function, but I can't believe
defconstant is so limited !


        Stefan

From: Lyman S. Taylor
Subject: Re: defconstant
Date: 
Message-ID: <4aq47u$1dk@pravda.cc.gatech.edu>
In article <··········@info.epfl.ch>,
Stefan Monnier <··············@lia.di.epfl.ch> wrote:
>Is it possible to use defconstant to define anything else than
>trivial values ?

  Yes...

>
>A file such as:
>
>        (defstruct s a)
>        (defconstant toto (make-s :a 1))

  However, I think this isn't what is in the file.  I loaded this into MCL 3.0, Lucid,
  Allegro 4.1 (RS/6000 ),  and Lispworks no problems...     However if I load 

        (defconstant toto (make-s :a 1))
        (defstruct s a)

   I get the local version of the error message below....       

>is refused by AllegroCL:
>
>        USER(26): :cl ~/tmp/toto.lisp
...
>        Error: attempt to call `MAKE-S' which is an undefined function.
>          [condition type: UNDEFINED-FUNCTION]
>
>I can work around this by defining toto as a defvar initialized to nil and then
>set it to some (constant) value inside an init function, but I can't believe
>defconstant is so limited !

 I'd stay the problem is your copy of allegro....





-- 
					
Lyman S. Taylor           "Computers are too reliable to replace
(·····@cc.gatech.edu)     	 humans effectively."
			        Commander Nathan Spring, "Starcops"
From: Lyman S. Taylor
Subject: Re: defconstant
Date: 
Message-ID: <4aq96q$3bl@pravda.cc.gatech.edu>
In article <··········@pravda.cc.gatech.edu>,
Lyman S. Taylor <·····@cc.gatech.edu> wrote:
>In article <··········@info.epfl.ch>,

> I'd stay the problem is your copy of allegro....
>
   As has been pointed in mail ( gee the internet is fast). The compiler wants to
   eval the  the expression make-s but even those the code has been compiled 
   it hasn't been loaded yet.

   Solution.  Load the code.  Then compile it.   That does work.
   If the code file is rather later then just decouple the defstruct into a smaller
   file and then load it and then compile.

    pretoto.lisp

		(defstruct s a )

    toto.lisp
                (defstruct s a )
		(defconstant toto (make-s :a 1 ))

   
    CL-USER> (load "pretoto.lisp" )
	
    CL-USER> (compile-file "toto.lisp") 

    A bit of a hack but it works....  [ If this a complicated system you can 
    add a dependency between pretoto.lisp and toto.lisp. And you have to keep the
    struct definitions synchronized. ] 




-- 
					
Lyman S. Taylor           "Computers are too reliable to replace
(·····@cc.gatech.edu)     	 humans effectively."
			        Commander Nathan Spring, "Starcops"
From: Kelly Murray
Subject: Re: defconstant
Date: 
Message-ID: <4aqsch$27f@sparky.franz.com>
>> >In article <··········@info.epfl.ch>,
>> 
>>    As has been pointed in mail ( gee the internet is fast). The compiler wants to
>>    eval the  the expression make-s but even those the code has been compiled 
>>    it hasn't been loaded yet.
>> 
>>    Solution.  Load the code.  Then compile it.   That does work.

The more direct solution (which you'll get 10 replies), is to wrap 
(eval-when (compile load)  )  around the defstruct form so it gets
evaluated by the compiler during compile-time and thus is defined
before the defconstant expression gets compiled.

-Kelly Murray    ···@franz.com    http://www.franz.com
From: Erik Naggum
Subject: Re: defconstant
Date: 
Message-ID: <19951215T021024Z@arcana.naggum.no>
[Stefan Monnier]

|   Is it possible to use defconstant to define anything else than trivial
|   values?
|   
|   A file such as:
|   
|           (defstruct s a)
|           (defconstant toto (make-s :a 1))
|           
|   is refused by AllegroCL:
|   
|           USER(26): :cl ~/tmp/toto.lisp
|           ; --- Compiling file /users/monnier/tmp/toto.lisp ---
|           ; Compiling MAKE-S
|           ; While compiling (:TOP-LEVEL-FORM "toto.lisp" 2):
|           Error: attempt to call `MAKE-S' which is an undefined function.
|             [condition type: UNDEFINED-FUNCTION]
|   
|   I can work around this by defining toto as a defvar initialized to nil
|   and then set it to some (constant) value inside an init function, but I
|   can't believe defconstant is so limited!

would `eval-when' provide a solution to this problem (i.e., around the
first `defstruct')?  I don't fully understand the CLtL2 or ANSI CL
`eval-when' description, so this is a guess:

    (eval-when (:compile-toplevel :load-toplevel :execute)
      (defstruct s a))
    (defconstant toto (make-s :a 1))

this works with CMUCL 17f, GCL 2.1 and CLISP 1995-08-12, albeit with the
deprecated symbols `compile', `load', and `eval', but I'd like to know if
this is the right way to do it.  comments?

#<Erik 3027982224>
-- 
suppose we actually were immortal...
what is the opposite of living your life as if every day were your last?
From: Bruno Haible
Subject: Re: defconstant
Date: 
Message-ID: <4bf7de$63a@nz12.rz.uni-karlsruhe.de>
> Is it possible to use defconstant to define anything else than
> trivial values ?

No, not in Common Lisp. CLtL2 states (in section 25.1.3) that the
value-form in a `defconstant' form must be evaluable at compile-time,
and that you must ensure this yourself.

Except for compatibility with existing CL implementations, there is
no justification for this restriction. Good compilers should evaluate
the form when they can, and postpone evaluation until runtime when
they cannot. Just as they do for constant expression elimination.

There is no such restriction in ISLisp, btw.


Bruno Haible                                     email: <······@ilog.fr>
Software Engineer                                phone: +33-1-49083585
From: Tim Bradshaw
Subject: Re: defconstant
Date: 
Message-ID: <TFB.96Jan3175358@scarp.ed.ac.uk>
* Bruno Haible wrote:
>> Is it possible to use defconstant to define anything else than
>> trivial values ?

> No, not in Common Lisp. CLtL2 states (in section 25.1.3) that the
> value-form in a `defconstant' form must be evaluable at compile-time,
> and that you must ensure this yourself.

While this is perhaps a draconian restriction, it certainly doesn't
imply that you can't use defconstant to define only trivial things --
you just have to make sure, via eval-when or whatever that they are
known at compile time.

--tim