I was trying to write a moo-like program and ran into
this problem. I want things to have a location and I
want places to have a list of contents. Seemed simple
enough.
(defstruct thing name location)
(defstruct place name contents)
So, make one of each.
(setf daniel (make-thing :name "Daniel"))
(setf closet (make-place :name "Closet"))
And put Daniel in the closet.
(setf (thing-location daniel) closet)
(setf (place-contents closet) daniel)
Oops. Adding Daniel to the contents list throws clisp
and cmucl for a loop. I could put daniel in the 'closet
but I don't expect everything should have a symbol
associated with it.
Would someone please point me in the right direction.
Thanks.
(This is a personal learning exercise, not classwork.
I'd take a class if it were offered around here.)
In article <················@msu.edu>, Ed Symanzik <···@msu.edu> wrote:
>I was trying to write a moo-like program and ran into
>this problem. I want things to have a location and I
>want places to have a list of contents. Seemed simple
>enough.
>
>(defstruct thing name location)
>(defstruct place name contents)
>
>So, make one of each.
>
>(setf daniel (make-thing :name "Daniel"))
>(setf closet (make-place :name "Closet"))
>
>And put Daniel in the closet.
>
>(setf (thing-location daniel) closet)
>(setf (place-contents closet) daniel)
>
>Oops. Adding Daniel to the contents list throws clisp
>and cmucl for a loop. I could put daniel in the 'closet
>but I don't expect everything should have a symbol
>associated with it.
You said that the contents should be a *list*, but you just set it to
a single structure. Try:
(setf closet (make-place :name "Closet" :contents '()))
(push daniel (place-contents closet))
Also, make sure you have *PRINT-LEVEL* set to a small number, so that the
printer doesn't give a fit when it tries to print them (because they're
mutually recursive).
--
Barry Margolin, ······@genuity.net
Genuity, Woburn, 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.
Ed Symanzik wrote:
>
> I was trying to write a moo-like program and ran into
> this problem. I want things to have a location and I
> want places to have a list of contents. Seemed simple
> enough.
>
> (defstruct thing name location)
> (defstruct place name contents)
>
> So, make one of each.
>
> (setf daniel (make-thing :name "Daniel"))
> (setf closet (make-place :name "Closet"))
>
> And put Daniel in the closet.
>
> (setf (thing-location daniel) closet)
> (setf (place-contents closet) daniel)
>
> Oops. Adding Daniel to the contents list throws clisp
> and cmucl for a loop. I could put daniel in the 'closet
> but I don't expect everything should have a symbol
> associated with it.
(setq *print-circle* T)
--