From: Frederic Warin
Subject: Problem in Lucid Common Lisp
Date: 
Message-ID: <495@muller.loria.fr>
A friend who hasn't access to the news ask me to post the following message:

I have a big problem in Lucid Common Lisp (running on Sun Sparc Slc,
openwindow, SunOS 4.1.1). This is Sun Common Lisp 4.0.2


It will great if someone could help me.

The aim is :  generate lisp code for saving the value of variables.
As these variables are complex, I wanted to use the propertie offered by
setting the *print-structure* and *print-array* to the t value.
When one is printing the value of the structure, it will be done in detail
rather than an adress only.

The problem is : when the structure is a recursive one, some objects are not
referenced. They are just described as a #:g1234 (for example) object.
That means the package of the object is unknown. And that is not true.

My structure is too complex for giving here its description on detail, and
I didn't succeed in producing this problem with an another structure more
simple.

All I can do is simulate what is happening.

Here is the Lisp code I use :
=================================================
(in-package 'user)

(defstruct slot id next previous)

(setq z (make-slot :id 'z))
(setq y (make-slot :id 'y :next z))
(setq x (make-slot :id 'x :next y))
(setq w (make-slot :id 'w :next x))
(setq v (make-slot :id 'v :next w))
(setq u (make-slot :id 'u :next v))
(setq tt (make-slot :id 't :next u))
(setq s (make-slot :id 's :next tt))
(setq r (make-slot :id 'r :next s))
(setq q (make-slot :id 'q :next r))
(setq p (make-slot :id 'p :next q))
(setq o (make-slot :id 'o :next p))
(setq n (make-slot :id 'n :next o))
(setq m (make-slot :id 'm :next n))
(setq l (make-slot :id 'l :next m))
(setq k (make-slot :id 'k :next l))
(setq j (make-slot :id 'j :next k))
(setq i (make-slot :id 'i :next j))
(setq h (make-slot :id 'h :next i))
(setq g (make-slot :id 'g :next h))
(setq f (make-slot :id 'f :next g))
(setq e (make-slot :id 'e :next f))
(setq d (make-slot :id 'd :next e))
(setq c (make-slot :id 'c :next d))
(setq b (make-slot :id 'b :next c))
(setq a (make-slot :id 'a :next b))
(setf (slot-next z) a)

(setf (slot-previous a) a)
(setf (slot-previous b) b)
(setf (slot-previous c) c)
(setf (slot-previous d) d)
(setf (slot-previous e) e)
(setf (slot-previous f) f)
(setf (slot-previous g) g)
(setf (slot-previous h) h)
(setf (slot-previous i) i)
(setf (slot-previous j) j)
(setf (slot-previous k) k)
(setf (slot-previous l) l)
(setf (slot-previous m) m)
(setf (slot-previous n) n)
(setf (slot-previous o) o)
(setf (slot-previous p) p)
(setf (slot-previous q) q)
(setf (slot-previous r) r)
(setf (slot-previous s) s)
(setf (slot-previous tt) tt)
(setf (slot-previous u) u)
(setf (slot-previous v) v)
(setf (slot-previous w) w)
(setf (slot-previous x) x)
(setf (slot-previous y) y)
(setf (slot-previous z) z)

(defvar *stream*)

(defun open-stream (file)
  (setq *stream* (open file :direction :output :if-exists :supersede)))
(defun write-stream (text)
  (write text 
	 :stream *stream*
	 :circle t 
	 :escape t 
	 :pretty nil 
	 :array t)
  (format *stream* "~%"))

(defun close-stream ()
  (close *stream*))


(defvar *file* "file")

(setq *print-structure* t)
(setq *print-array* t)

(defun make-save ()
  (open-stream *file*)
  (write-stream '(in-package 'user))
  (write-stream `(setf *a* ,a))
  (close-stream)
  )

(make-save)
(load "file")
(print *a*)
=================================================

According to the lisp code above, the content of the file will be :

(in-package (quote user))
(setf *a* #1=#S(slot id a next #2=#S(slot id b next #3=#S(slot id c next #4=#S
(slot id d next #5=#S(slot id e next #6=#S(slot id f next #7=#S
(slot id g next #8=#S(slot id h next #9=#S(slot id i next #10=#S
(slot id j next #11=#S(slot id k next #12=#S(slot id l next #13=#S
(slot id m next #14=#S(slot id n next #15=#S(slot id o next #16=#S
(slot id p next #17=#S(slot id q next #18=#S(slot id r next #19=#S
(slot id s next #20=#S(slot id t next #21=#S(slot id u next #22=#S
(slot id v next #23=#S(slot id w next #24=#S(slot id x next #25=#S
(slot id y next #26=#S(slot id z next #1# previous #26#) 
previous #25#) previous #24#) previous #23#) previous #22#) 
previous #21#) previous #20#) previous #19#) previous #18#) 
previous #17#) previous #16#) previous #15#) previous #14#) 
previous #13#) previous #12#) previous #11#) previous #10#) 
previous #9#) previous #8#) previous #7#) previous #6#) previous #5#) 
previous #4#) previous #3#) previous #2#) previous #1#))


And the value of *a* after loading the file will be :

#1=#S(slot id a next #2=#S(slot id b next #3=#S(slot id c next #4=#S
(slot id d next #5=#S(slot id e next #6=#S(slot id f next #7=#S
(slot id g next #8=#S(slot id h next #9=#S(slot id i next #10=#S
(slot id j next #11=#S(slot id k next #12=#S(slot id l next #13=#S
(slot id m next #14=#S(slot id n next #S(slot id o next #16=#S
(slot id p next #S(slot id q next #S(slot id r next #19=#S
(slot id s next #20=#S(slot id t next #21=#S(slot id u next #22=#S
(slot id v next #23=#S(slot id w next #24=#S(slot id x next #25=#S
(slot id y next #26=#S(slot id z next #1# previous #26#) previous #25#) 
previous #24#) previous #23#) previous #22#) previous #21#) previous #20#) 
previous #19#) previous #18=#:g2076) previous #17=#:g2077) previous #16#) 
previous #:g2077) previous #14#) previous #13#) previous #12#) previous #11#) 
previous #10#) previous #9#) previous #8#) previous #7#) previous #6#) 
previous #5#) previous #4#) previous #3#) previous #2#) previous #1#) 

In this example, the structures #17# and #18# are not existing any more. So 
the references to these objects are replaced by #18=#:g2077 and #17=#:g2076. 
That means it is object which does not belong to a package ...

A second problem is that #15# is not referenced any more, and the pointer on it
is replaced by : #:g2077.

This example is just a simulation, and I'm not sure of the precision of all the
data. But I hope it globally represents my problem and that you understand it.


-- 

Thanks in advance for her.
		
	Frederic


·····@loria.fr
Frederic Warin		Crin/Inria Lorraine	France