Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

defconstant

39 views
Skip to first unread message

Stefan Monnier

unread,
Dec 14, 1995, 3:00:00 AM12/14/95
to
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

Lyman S. Taylor

unread,
Dec 14, 1995, 3:00:00 AM12/14/95
to
In article <4aptsr$j...@info.epfl.ch>,

Stefan Monnier <stefan....@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
(ly...@cc.gatech.edu) humans effectively."
Commander Nathan Spring, "Starcops"

Lyman S. Taylor

unread,
Dec 14, 1995, 3:00:00 AM12/14/95
to
In article <4aq47u$1...@pravda.cc.gatech.edu>,
Lyman S. Taylor <ly...@cc.gatech.edu> wrote:
>In article <4aptsr$j...@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. ]

Erik Naggum

unread,
Dec 15, 1995, 3:00:00 AM12/15/95
to
[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?

Kelly Murray

unread,
Dec 15, 1995, 3:00:00 AM12/15/95
to
>> >In article <4aptsr$j...@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 k...@franz.com http://www.franz.com

Bruno Haible

unread,
Dec 22, 1995, 3:00:00 AM12/22/95
to
> 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: <hai...@ilog.fr>
Software Engineer phone: +33-1-49083585


Tim Bradshaw

unread,
Jan 3, 1996, 3:00:00 AM1/3/96
to
* 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

0 new messages