the decider

pull/2/head
Matthew Butterick 9 years ago
parent 90b8680bd7
commit bc489f37ab

@ -1,36 +0,0 @@
#lang br/quicklang
(define (read-syntax src-path in-port)
(define args (port->list read in-port))
(define module-datum `(module stacker-mod br/demo/stacker
,@args))
(datum->syntax #f module-datum))
(provide read-syntax)
(define-macro (stacker-module-begin ARG ...)
#'(#%module-begin
(push ARG) ...
(display (first stack))))
(provide (rename-out [stacker-module-begin #%module-begin]))
(define stack empty)
(define (pop-stack!)
(define first-item (first stack))
(set! stack (rest stack))
first-item)
(define (push-stack! elem) (set! stack (cons elem stack)))
(define (push arg)
(cond
[(number? arg) (push-stack! arg)]
[else
(define op-result (arg (pop-stack!) (pop-stack!)))
(push-stack! op-result)]))
(provide + *)
(module+ test
(require rackunit)
(check-equal? (with-output-to-string (λ () (dynamic-require "stacker-test.rkt" #f))) "36"))

@ -1,27 +1,34 @@
#lang br/quicklang #lang br/quicklang
(define (stacker-read-syntax src-path in-port) (define (read-syntax src-path in-port)
(define args (port->list read in-port)) (define arg-datums (port->list read in-port))
(with-pattern ([(ARG ...) args]) (define module-datum `(module mod-name br/demo/stacker
(strip-identifier-bindings ,@arg-datums))
#'(module stacker-mod br/demo/stacker (datum->syntax #f module-datum))
ARG ...))))
(provide read-syntax) (provide read-syntax)
(define-macro (stacker-module-begin ARG ...) (define-macro (stacker-module-begin ARG-STX ...)
#'(#%module-begin #'(#%module-begin
(push ARG) ... (put ARG-STX) ...
(display (first stack)))) (display (pop-stack!))))
(provide (rename-out [stacker-module-begin #%module-begin])) (provide (rename-out [stacker-module-begin #%module-begin]))
(define stack empty) (define stack empty)
(define (push arg) (define (pop-stack!)
(define item (first stack))
(set! stack (rest stack))
item)
(define (push-stack! item)
(set! stack (cons item stack)))
(define (put arg)
(cond (cond
[(number? arg) (set! stack (cons arg stack))] [(number? arg) (push-stack! arg)]
[else [else
(define op-result (arg (first stack) (second stack))) (define op-result (arg (pop-stack!) (pop-stack!)))
(set! stack (cons op-result (drop stack 2)))])) (push-stack! op-result)]))
(provide + *) (provide + *)

@ -1,6 +0,0 @@
#lang reader br/demo/stacker1
4
8
+
3
*

@ -1,36 +0,0 @@
#lang br/quicklang
(define (read-syntax src-path in-port)
(define args (port->list read in-port))
(define module-datum `(module stacker-mod br/demo/stacker1
,@args))
(datum->syntax #f module-datum))
(provide read-syntax)
(define-macro (stacker-module-begin ARG ...)
#'(#%module-begin
(push ARG) ...
(display (first stack))))
(provide (rename-out [stacker-module-begin #%module-begin]))
(define stack empty)
(define (pop-stack!)
(define item (first stack))
(set! stack (rest stack))
item)
(define (push-stack! item) (set! stack (cons item stack)))
(define (push arg)
(cond
[(number? arg) (push-stack! arg)]
[else
(define op-result (arg (pop-stack!) (pop-stack!)))
(push-stack! op-result)]))
(provide + *)
(module+ test
(require rackunit)
(check-equal? (with-output-to-string (λ () (dynamic-require "stacker1-test.rkt" #f))) "36"))
Loading…
Cancel
Save