I'm getting hopelessly confused by aliens. Rather than try to explain
it all at once, I've reduced one of my questions to its simplest
possible form. If anyone can explain this behavior to me, I would be
greatful. The question is in the comments in the included file. This
file can be compiled and loaded.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(declaim (optimize (speed 1) (safety 3) (debug 3)))
(alien:def-alien-type foo
(alien:struct foo (uint c-call:unsigned-int)))
(defvar *f* (alien:make-alien foo))
;; Either of these would work:
;; (setf (alien:slot *f* 'uint) 35)
;; (setf (alien:slot (the (alien:alien (* foo)) *f*) 'uint) 35)
;; This would causes a load-time error:
;; (setf (alien:slot (the (alien:alien foo) *f*) 'uint) 35)
;; This is understable, because *f* is an (alien:alien (* foo)),
;; NOT an (alien:alien foo)
;; But why does this work????
(defun set-uint-to-35-bad (foo)
(setf (alien:slot (the (alien:alien foo) foo) 'uint) 35))
(set-uint-to-35-bad *f*)
;; What's different outside a function? I would expect a load-time
;; error, but I do not get one. In fact, set-uint-to-35-bad seems to
;; always work fine, even though the "the" declaration is "wrong". It
;; also seems to have the non-consing properties of a variant in which
;; the "the" declaration is correct. I just don't get it.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
More generally, is using "the" declarations unpredictable or risky
somehow?
What I'm *really* trying to do is make a very slight modification to
UFFI so that slot accesses become type declared; I was hoping to do it
with "the" rather than "declare" type declarations because this allows
me to avoid mucking with def-setf-expander. I'm not sure what I want
is possible at all, actually, because I'm not clear that the UFFI
syntax properly distinguishes between objects of type foo and pointers to
objects of type foo, but that's a question for the UFFI-list and
another day.
Any help is as always appreciated.
Cheers,
rif