Skip to content

Instantly share code, notes, and snippets.

@kana
Created May 1, 2010 08:01
Show Gist options
  • Save kana/386143 to your computer and use it in GitHub Desktop.
Save kana/386143 to your computer and use it in GitHub Desktop.
; How do I implement the following macro in R5RS?
;
; (define! x)
; ==> (define x "x")
; (define x "x!")
(define-syntax define!
(syntax-rules ()
[(_ name)
(define name (symbol->string 'name))
(define ... ...)]))
; In Gauche.
; But it's ugly. Isn't there smarter solution?
(define-syntax define!
(syntax-rules ()
[(_ name)
(let1 name!s (string-append (symbol->string 'name) "!")
(map (cut eval <> (current-module))
`((define ,(string->symbol name!s) ,name!s)
(define name (symbol->string 'name)))))]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment