Lisp HUG Maillist Archive

Switching packages

Why after
 
(in-package :bar)
(eval-when (compile load)
    (let ((*package* (find-package :foo)))
        (defun foofun ()
            )))
 
foofun is defined in :bar package?
 
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)
 
Thank you,
Denis.

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

-- 
Pascal Costanza, mailto:pc@p-cos.net, http://p-cos.net
Vrije Universiteit Brussel, Programming Technology Lab
Pleinlaan 2, B-1050 Brussel, Belgium




Re: Switching packages


On Nov 29, 2005, at 5:09 PM, 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?
 
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)
 
Thank you,
Denis.



Tim Bradshaw's read-time-packages may give you what you  want:
<http://www.tfeb.org/lisp/hax.html#READ-PACKAGES>

regards,

Ralph

Raffael Cavallaro, Ph.D.
raffaelcavallaro@mac.com

Updated at: 2020-12-10 08:49 UTC