[gambit-list] Is there a low level hack to define global macros?
Marc Feeley
feeley at iro.umontreal.ca
Sat Apr 11 15:25:26 EDT 2020
> On Apr 11, 2020, at 2:09 PM, Jörg F. Wittenberger <Joerg.Wittenberger at softeyes.net> wrote:
>
> Hi Marc,
>
> (guess this goes only for you ;-)
>
> While I wonder how I'd teach gambit to understand `define-values` in
> the repl (see other message)...
>
> There is this low level hack (helpful so far while too lazy to ask) to
> define new global variables at runtime:
>
> (define (doDEFINE! x v)
> (##make-global-var x)
> (##global-var-set! x v))
>
> (doDEFINE! 'result 42))
>
> result
> 42
>
The code is not 100% correct. It is better to do:
(define (doDEFINE! sym val) (##global-var-set! (##make-global-var sym) val))
> How would I define a macro (not evaluation arguments) at runtime instead
> of a procedure? Possible?
You can of course do:
> (eval '(define-macro (mymac x) `(begin ,x ,x)))
> (mymac (pp 'hello))
hello
hello
Otherwise, there’s a way with:
(##top-cte-add-macro! ##interaction-cte 'mymac ...)
but that uses internal procedures that are best left for internal use (they may soon change).
Marc
More information about the Gambit-list
mailing list