Re: Switching packages
On 29 Nov 2005, at 23:09, Denis Mashkevich wrote:
Why after
(in-package :bar)
(eval-when (compile load)
(let ((*package* (find-package :foo)))
(defun foofun ()
)))
foofun is defined in :bar package?
The Lisp reader interns symbols at read time, but the new binding for *package* is only activated at runtime. So when the code binds *package* to (find-package :foo) it's already too late: the symbol 'foofun was already read with the *package* bound to :bar.
The in-package macro works because forms are processed one at a time, so in-package can set *package* to a new value, and all subsequent forms in a file are processed with *package* bound to that new value.
Backround: I am trying to find a clean way to port
to lispworks loads of allegro code which uses this
peculiar syntax:
foo::(compile/execute this list in foo package)
I don't think it's possible to get the same effect with that syntax, at least I don't see a straightforward way to do that.
If it is acceptable to you, you could define a read macro to do something similar. For example, you could make something like the following work:
#!foo(read this list in foo package)
See set-macro-character and set-dispatch-macro-character for details.
Cheers,
Pascal
--
Vrije Universiteit Brussel, Programming Technology Lab
Pleinlaan 2, B-1050 Brussel, Belgium