Open jpellegrini opened 1 month ago
I forgot the explain why I used select-module
inside a let
: I was trying to write a with-module
macro, and it didn't work...
(define-macro (with-module mod . body)
(let ((old-module (gensym 'old-module))
(res (gensym 'res)))
`(let ((,old-module (current-module)))
(select-module ,mod)
(let ((,res (begin ,@body)))
(select-module ,old-module)
,res))))
But that didn't work for a couple of reasons (including the fact that I can't seem to guarantee that the current-module
symbol has the binding from the SCHEME
module)
When
select-module
is used inside aLET
, the result seems a bit confusing...I have read the source of
select-module
, but still can't see why this happens. Is the local scope somehow attached to the module? And when we change the module, the scope is gone?I have compared the bytecode for
(select-module x)
to the bytecode for the first expression (above):This second one ends with
local-ref0
(before theleave-let
), so it "should" have returned the value ofa
... unless thislocal-ref0
actually depends on the current module. (?)