[Openmcl-devel] Changing the default package

Gary Byers gb at clozure.com
Fri Mar 14 05:59:16 PDT 2014


When a thread starts up, it does something like:


(let* ((*package* *package*) ; actually done via PROGV
         ...)
    ...)
That establishes a thread-specific dynamic binding of the variable, and the
earliest such dynamic binding shadows the global static binding of *PACKAGE*.
(There is or used to be a tutorial on the net that explains the concept
of "shadowing" better than I can at 6 AM ...)  That dynamic binding remains
in effect throughout (almost all of) the thread's lifetime, and assignments
to and references of the variable involve the value established in this
(or the most recent) dynamic binding; the static/global binding is only
visuble during the brief periods before and after the LET* (PROGV) is in
effect.

The static binding is visible on the right-hand side of that LET*; if we
change the value associated with that static binding, we'll change the
value used to establish dynamic bindings in subsequently created threads.
The "value associated with the static binding" of a symbol ia stored in
the symbol's "value cell", but there's no public ways of accessing that cell.

Fortunately, there are private ways of doing so:

(ccl::%sym-global-value symbol)           ; access the value cell of SYMBOL
(ccl::%set-sym-global-value symbol value) ; set the value cell of SYMBOL to VALUE

These functions aren't inherently dangerous in and of themselves, but they
do give you enough rope to hang yourself with.  Using internal functions always
involves the risk that thos functions disappear or silently change in the future,

(ccl::%set-sym-global-value '*package* (find-package "FOO"))

should do what you want.




On Thu, 13 Mar 2014, Ron Garret wrote:

> I would like to change the default package, i.e. the package that is in place when a new listener is spawned or a new window is opened.  The following seems to work:
>
> (CCL::DEF-STANDARD-INITIAL-BINDING *package* my-package)
> (setf (symbol-value-in-process '*package* ccl::*initial-process*) my-package)
>
> but this second thing in particular feels fraught with peril.  If I change the value of *package* in the initial process, will that screw things up?  Is there some other way of achieving what I want?
>
> Thanks,
> rg
>
>



More information about the Openmcl-devel mailing list