For Programmers: Free Programming Magazines  


Home > Archive > Lisp > February 2008 > Re: How does the compiler decide that its ok to delete unused









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: How does the compiler decide that its ok to delete unused
Andy Chambers

2008-02-22, 8:12 am

On Feb 22, 12:55 pm, Maciej Katafiasz <mathr...@gmail.com> wrote:
> Den Fri, 22 Feb 2008 03:16:07 -0800 skrev Andy Chambers:
>
>
>
>
>
> The problem is not with the compiler, but with your code.


I didn't mean to imply that the compiler was wrong. My experience
tells me that when something doesn't work the way I expect, its
because I don't understand it properly.

> 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?

Cheers,
Andy
Rob Warnock

2008-02-22, 8:12 am

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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com