Quote:Original post by Flatlander
I'm not a language lawyer but since
(defstruct foo
bar)
(defun get-foo ()
(list #.(make-foo :bar 'bar)))
(eq (car (get-foo)) (car (get-foo)))
=> T
in both CMUCL and Lispworks, it looks like the struct in this case really is a literal ("...referenced directly in a program rather than being computed by the program...") object.
Yes, you're quite right. The result of evaluating the #. form is #S(VEC :X 0 :Y 0 :Z 0) which is a literal by virtue of being self-evaluating.
I think the language of the standard is a little confusing when it talks about structures appearing in constants, when the problem is that the structure appears as a constant -- the backquote form has nothing do with it.
In CMUCL, I get an error when compiling the above code. I must first put the defstruct in an (eval-when (:compile-toplevel) ...), since otherwise MAKE-FOO isn't visible when it's used. Then there's the error about not being able to dump the constant.
I don't quite see why there couldn't be a default make-load-form: it's trivial to 'pickle' the vector so-created, its print form -- #S(VEC :X 0 :Y 0 :Z 0) -- can be read directly, and in general that's the case for all structs: the only exceptions are those structs which contain unreadable objects in their slots, such as a stream.