add `format-datums`

pull/2/head
Matthew Butterick 9 years ago
parent 37951c7198
commit 99ebc4f804

@ -26,6 +26,9 @@
(syntax->datum arg)
arg)) args))))
(define (format-datums datum-template args)
(map (λ(arg) (format-datum datum-template arg)) args))
(module+ test
(require rackunit syntax/datum)
(check-equal? (string->datum "foo") 'foo)
@ -36,4 +39,5 @@
(check-equal? (format-datum '(~a-bar-~a) #'foo #'zam) '(foo-bar-zam))
(check-equal? (format-datum (datum (~a-bar-~a)) "foo" "zam") '(foo-bar-zam))
(check-equal? (format-datum '~a "foo") 'foo)
(check-equal? (format-datum (datum ~a) "foo") 'foo))
(check-equal? (format-datum (datum ~a) "foo") 'foo)
(check-equal? (format-datums '(put ~a) '("foo" "zam")) '((put foo) (put zam))))

@ -1,15 +1,16 @@
#lang br/quicklang
(define (read-syntax src-path in-port)
(define arg-datums (port->list read in-port))
(define args (port->list read in-port))
(define arg-datums (format-datums '(handle ~a) args))
(define module-datum `(module mod-name br/demo/stacker
,@arg-datums))
(datum->syntax #f module-datum))
(provide read-syntax)
(define-macro (stacker-module-begin ARG-STX ...)
(define-macro (stacker-module-begin ARG-DATUM-STX ...)
#'(#%module-begin
(put ARG-STX) ...
ARG-DATUM-STX ...
(display (pop-stack!))))
(provide (rename-out [stacker-module-begin #%module-begin]))
@ -23,14 +24,14 @@
(define (push-stack! item)
(set! stack (cons item stack)))
(define (put arg)
(define (handle arg)
(cond
[(number? arg) (push-stack! arg)]
[else
(define op-result (arg (pop-stack!) (pop-stack!)))
(push-stack! op-result)]))
(provide + *)
(provide handle + *)
(module+ test
(require rackunit)

Loading…
Cancel
Save