Skip to content

Instantly share code, notes, and snippets.

test gist
test test
one two three
@awwx
awwx / mac.rkt
Created April 27, 2011 18:48
Arc style macros in the racket/load language
#lang racket
(require mzlib/defmacro)
(provide mac)
(define-for-syntax macros-at-compile-time (make-hash))
(define-syntax macros-at-run-time
(lambda (stx)
(mac do args
`((lambda () ,@args)))
(do (display "using ")
(display "Arc macro\n"))
using Arc macro
@awwx
awwx / do-example.rkt
Created April 28, 2011 15:11
"do" macro in racket/load
#lang racket/load
(require "mac.rkt")
(mac do args
`((lambda () ,@args)))
> (do (display "using ")
(display "Arc macro\n"))
using Arc macro
> (define-syntax-rule (foo)
(do (display "Racket macro ")
(display "using Arc macro\n")))
> (foo)
Racket macro using Arc macro
> (define-syntax-rule (bar-helper)
(display "Racket macro\n"))
> (mac bar ()
`(do (display "Arc macro using ")
arc> x
Error: reference to undefined identifier: _x
arc> (namespace-set (this-namespace) 'x 123)
nil
arc> x
123
arc> (= other (new-arc))
#hash((racket-namespace* . #<namespace:0>))
arc> (namespace-get other 'car)
#<procedure:arc-car>
arc> (namespace-get other 'map)
Error: namespace-variable-value: _map is not defined