Re: sb-thread:make-thread sets thread's package to CL-USER
Michał "phoe" Herda via Sbcl-help <[email protected]>
| Newsgroups | gmane.lisp.steel-bank.general |
|---|---|
| Message-ID | <[email protected]> |
Yes. It's possible that your REPL bound *PACKAGE* somewhere along the way and that this is the binding you are seeing and modifying; this binding is effectively thread-local. If you want to copy the value of that dynamic binding to another thread, use something along the line of: (let ((package *package*)) (sb-thread:make-thread (lambda () (let ((*package* package)) ...)))) On 12.06.2024 23:28, Raimondas K. wrote: > (sb-ext:symbol-global-value '*package*) both in parent thread > and new thread return #<PACKAGE "COMMON-LISP-USER"> > > Thank you for the pointer to the manual – I think, this explains what > I am seeing: > "threads do not inherit dynamic bindings from the parent thread" > > > > On Wed, Jun 12, 2024 at 5:14 PM Michał "phoe" Herda via Sbcl-help > <[email protected]> wrote: > > What does (sb-ext:symbol-global-value '*package*) return in your > REPL? Is it consistent with what > https://www.sbcl.org/manual/#Special-Variables says? > > On 12.06.2024 22:58, Raimondas K. wrote: >> The *package* value in the new thread is not NIL and not what was >> in the calling thread, >> so the question whether the binding was not retained or set to an >> unexpected value >> is not as interesting as what the behaviour should be, logically. >> >> >> On Wed, Jun 12, 2024 at 4:41 PM Stas Boukarev >> <[email protected]> wrote: >> >> It doesn't set anything, it just doesn't retain your binding >> of *pacakge* at the time of calling make-thread. >> >> On Wed, Jun 12, 2024 at 11:37 PM Raimondas K. >> <[email protected]> wrote: >> >> I don't see this explicitly documented either way, >> but it looks that, empirically, the *package* inside the >> newly created thread is set to COMMON-LISP-USER. >> >> To demonstrate >> (defpackage :my (:use :cl)) >> (in-package :my) >> >> (defun test () >> (format *standard-output* "in TEST thread: package >> ~a~%" *package*)) >> >> (format *standard-output* "in MAIN thread: package ~a~%" >> *package*) >> >> (sb-thread:make-thread #'test >> :arguments '() >> :name "test") >> >> SBCL 2.3.2 prints out >> in MAIN thread: package #<PACKAGE "MY"> >> in TEST thread: package #<PACKAGE "COMMON-LISP-USER"> >> >> Not sure if this is how it is supposed to work; I find this >> behaviour counterintuitive, c/w for instance, with (load >> "file"). >> >> =R. >> >> >> _______________________________________________ >> Sbcl-help mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/sbcl-help >> >> >> >> _______________________________________________ >> Sbcl-help mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/sbcl-help > _______________________________________________ > Sbcl-help mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/sbcl-help > _______________________________________________ Sbcl-help mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sbcl-help