From: Karol Skocik
Subject: problem - works in REPL, but not with source
Date: 
Message-ID: <1127652636.780999.309250@f14g2000cwb.googlegroups.com>
Hi,
  I have problem with CMUCL 19b/Linux. In my source, there is something
like this :

(defstruct var)

(defvar *var* (list (make-instance 'var)))

which complains when compiling with this message :

Execution of a form compiled with errors:
 (#<Closure Over Function "DEFUN MAKE-DEFSTRUCT-ALLOCATION-FUNCTION"
    {58495289}>)
   [Condition of type KERNEL:SIMPLE-PROGRAM-ERROR]

Restarts:
  0: [CONTINUE] Return NIL from load of
#P"/home/neptun/.asdf-install-dir/site/gi/prod.x86f".
  1: [ABORT] Abort SLIME compilation.
  2: [ABORT] Abort handling SLIME request.
  3: [ABORT] Return to Top-Level.

Backtrace:
  0: ((MAKE-INSTANCE VAR))
  1: (C::DO-CALL #<Code Object "Top-Level Form" {584A0CA7}> 38 39 4
...)
  2: (LISP::FOP-FUNCALL-FOR-EFFECT)
  3: (LISP::LOAD-GROUP #<Stream for file
"/home/neptun/.asdf-install-dir/site/gi/prod.x86f">)
  4: (LISP::FASLOAD #<Stream for file
"/home/neptun/.asdf-install-dir/site/gi/prod.x86f">)
  5: (LISP::INTERNAL-LOAD
#P"/home/neptun/.asdf-install-dir/site/gi/prod.x86f"
#P"/home/neptun/.asdf-install-dir/site/gi/prod.x86f" :ERROR :BINARY)
  6: (LISP::INTERNAL-LOAD
#P"/home/neptun/.asdf-install-dir/site/gi/prod.x86f"
#P"/home/neptun/.asdf-install-dir/site/gi/prod.x86f" :ERROR NIL)
....

When I looked closer - I removed the (defvar *var* ...)
and compiled again - successfully. When I did in REPL :

; /home/neptun/.asdf-install-dir/site/gi/prod.x86f written.
; Compilation finished in 0:00:01.
; Loading #P"/home/neptun/.asdf-install-dir/site/gi/prod.x86f".
GI> (defvar *var* (list (make-instance 'var)))
*VAR*
GI> *var*
(#S(VAR))

I got what I want. So I am curious :

1.) Why it does not work with source? It looks like that in defvar, the
compiler does not know about the (defstruct var) which is compiled
sooner than (defvar *var* (list (make-instance 'var))) but this is of
course stupid, the problem must be somewhere else...

2.) How to make it work? I mean, what I want to do is to have a list of
already constructed structures and objects in a list directly in fasl
file, so that when I load fasl, the objects are already constructed.

Thanks for any ideas,
  Karol
From: Pascal Bourguignon
Subject: Re: problem - works in REPL, but not with source
Date: 
Message-ID: <8764son3di.fsf@thalassa.informatimago.com>
"Karol Skocik" <············@gmail.com> writes:

> Hi,
>   I have problem with CMUCL 19b/Linux. In my source, there is something
> like this :
>
> (defstruct var)
>
> (defvar *var* (list (make-instance 'var)))

A structure named X is allocated with (make-X), not (make-instance 'X).
Considering a structure type as a CLOS class is implementation dependant.


> [...]
> When I looked closer - I removed the (defvar *var* ...)
> and compiled again - successfully. When I did in REPL :
>
> ; /home/neptun/.asdf-install-dir/site/gi/prod.x86f written.
> ; Compilation finished in 0:00:01.
> ; Loading #P"/home/neptun/.asdf-install-dir/site/gi/prod.x86f".
> GI> (defvar *var* (list (make-instance 'var)))
> *VAR*
> GI> *var*
> (#S(VAR))
>
> I got what I want. So I am curious :
>
> 1.) Why it does not work with source? It looks like that in defvar, the
> compiler does not know about the (defstruct var) which is compiled
> sooner than (defvar *var* (list (make-instance 'var))) but this is of
> course stupid, the problem must be somewhere else...

cmucl contains two implementations: an interpreter and a compiler.
They rightly differ in their semantics.  The REPL uses the interpreter.


> 2.) How to make it work? I mean, what I want to do is to have a list of
> already constructed structures and objects in a list directly in fasl
> file, so that when I load fasl, the objects are already constructed.

Read CLHS.
http://www.lispworks.com/documentation/HyperSpec/Body/m_defstr.htm


-- 
"Remember, Information is not knowledge; Knowledge is not Wisdom;
Wisdom is not truth; Truth is not beauty; Beauty is not love;
Love is not music; Music is the best." -- Frank Zappa