Andy Chambers <achambers.home@googlemail.com> wrote:
+---------------
| Maciej Katafiasz <mathr...@gmail.com> wrote:
| > skrev Andy Chambers:
| > > (defmethod refs ((odm odm))
| > > (with-accessors ((doc doc)) odm
| > > (?let ((items `(// :|ItemRef|))
| > > (codelists `(// :|CodeListRef|))
| > > (groups `(// :|ItemGroupRef|))
| > > (forms `(// :|FormRef|))
| > > (events `(// :|StudyEventRef|)))
| > > (reduce (lambda (l1 l2)
| > > (union l1 l2))
| > > (mapcar (lambda (f)
| > > (funcall f doc)))))))
| >
| > > I've created a macro that makes the ?let form above expand into a labels
| > > form making items, codelists etc available as functions of one arg. A
| > > note from the compiler says that it deleted them during macroexpansion,
| > > presumably because it thinks they're not being used. This means that
| > > when funcall tries to call them, they don't exist. I can work around
| > > this but I'm interested in how the compiler decides its ok to delete
| > > them.
| >
| > The problem is not with the compiler, but with your code.
...
| > You can't access the lexical environment other than by forms textually
| > enclosed by it.
|
| So that means if the functions defined by labels don't appear as the
| operator in any of its sub-forms, they're safe to be deleted?
+---------------
No, you can FUNCALL them, just not as *symbols*, which get the global
values. But you can use the FUNCTION special operator to access the
lexical functional values. That is, instead of (FUNCALL 'ITEMS ...) you
need to use (FUNCALL (FUNCTION ITEMS) ...) a.k.a. (FUNCALL #'ITEMS ...).
And you can even MAPCAR over them if you provide their *lexical* values,
e.g.:
(mapcar (lambda (f) (funcall f doc))
(list #'items #'codelists #'groups #'forms #'events))
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607