[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: POTHIERS%TUVA.SAINET.MFENET@NMFECC.ARPA
- From: email@example.com (firstname.lastname@example.org any day now)
- Date: Wed, 6 Apr 88 09:10 est
- Cc: COMMON-LISP@SAIL.STANFORD.EDU
- Comments: NOTE %acorn@oak... WILL BECOME @GOLD-HILL.COM ANY DAY NOW
Date: Tue, 5 Apr 88 11:29:13 PDT
Date: Tue, 5-APR-1988 10:55 MST
I'm trying to create structures on the fly. I have a problem with:
(defun test (&aux x)
(defstruct foo a b c)
(setf x (make-foo))
(setf (foo-a x) 1)
When TEST is interpreted, all is fine. When it is compiled the
function (foo-a) is undefined since it isn't created by defstruct
until run time. In my actual code FOO is a symbol that's build based
upon some args to TEST, therefore I can't simply put the defstruct at
the top level. Any ideas??
There are a few problems here. First, to compile (setf (foo-a x) 1)
you would have to have the structure predefined, since "setters" are
not even required to be callable functions by common lisp.
I have to ask why you have to do this in this fashion. It appears
you need to dynamically create named record "types". The way to do this
is not necessarily to evaluate a defstruct at run time.
I'd do it by inventing a meta-structure type.
(name (gensym) :type symbol)
(slots #() :type vector))
or something like that. Then I'd use the copier to create new
instances, the constructor to create the initial "prototype" instance,
etc. You'd have to create your own predicates for recognizing
them and relating them.
This is unfortunately, exactly the way you'd have to do it
in a statically typed programming language.