I am trying to write a wrapper for define that stores the values passed to it. I approached him in the children's steps (new to Lisp in general and even new to Scheme), but ran into a wall.
In Racket, I start with:
> (require (lib "defmacro.ss")) > (define-macro (mydefine thing definition) `(define ,thing ,definition)) > (mydefine a 9) > a 9
Ok, that works. Time to do something in the macro before s-exprs returns:
> (define-macro (mydefine thing definition) (display "This works") `(define ,thing ,definition)) > (mydefine a "bob") This works > a "bob"
Nice. But I can’t force him to set a global variable for life instead of displaying something:
> (define *myglobal* null) > (define-macro (mydefine thing definition) (set! *myglobal* "This does not") `(define ,thing ,definition)) > (mydefine a ":-(") set!: cannot set identifier before its definition: *myglobal*
Any suggestions on how to do this would be greatly appreciated.
I suspect that I am trying to swim against the current one here, either by confusing the globals from the macro in the Schema, or using define-macro instead of examining the syntax specific to the scheme for creating the macro.
source share