update stacker versions
parent
6a1b143f3f
commit
3f295b66fa
@ -0,0 +1,36 @@
|
|||||||
|
#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"))
|
@ -0,0 +1,6 @@
|
|||||||
|
#lang reader br/demo/stacker0
|
||||||
|
4
|
||||||
|
8
|
||||||
|
+
|
||||||
|
3
|
||||||
|
*
|
@ -0,0 +1,38 @@
|
|||||||
|
#lang br/quicklang
|
||||||
|
|
||||||
|
(define (read-syntax src-path in-port)
|
||||||
|
(define args (port->lines in-port))
|
||||||
|
(define module-datum `(module stacker-mod br/demo/stacker0
|
||||||
|
,@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
|
||||||
|
[(equal? arg "+")
|
||||||
|
(define sum (+ (pop-stack!) (pop-stack!)))
|
||||||
|
(push-stack! sum)]
|
||||||
|
[(equal? arg "*")
|
||||||
|
(define product (* (pop-stack!) (pop-stack!)))
|
||||||
|
(push-stack! product)]
|
||||||
|
[(string->number arg) (push-stack! (string->number arg))]))
|
||||||
|
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(require rackunit)
|
||||||
|
(check-equal? (with-output-to-string (λ () (dynamic-require "stacker0-test.rkt" #f))) "36"))
|
@ -0,0 +1,6 @@
|
|||||||
|
#lang reader br/demo/stacker1
|
||||||
|
4
|
||||||
|
8
|
||||||
|
+
|
||||||
|
3
|
||||||
|
*
|
@ -0,0 +1,36 @@
|
|||||||
|
#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"))
|
@ -1,30 +1,26 @@
|
|||||||
#lang br/quicklang
|
#lang br/quicklang
|
||||||
#:read-syntax stacker-read-syntax
|
(provide read-syntax
|
||||||
#:#%module-begin stacker-module-begin
|
(rename-out [stacker-module-begin #%module-begin])
|
||||||
|
+ *)
|
||||||
|
|
||||||
(define (stacker-read-syntax src-path in-port)
|
(define (read-syntax src-path in-port)
|
||||||
(define stack-args (port->list read in-port))
|
(define args (port->list read in-port))
|
||||||
(with-pattern ([(STACK-ARG ...) stack-args])
|
(define module-datum `(module stacker2-mod br/demo/stacker2
|
||||||
(strip-identifier-bindings
|
,@args))
|
||||||
#'(module stacker2-mod br/demo/stacker2
|
(datum->syntax #f module-datum))
|
||||||
STACK-ARG ...))))
|
|
||||||
|
|
||||||
(define-macro (stacker-module-begin STACK-ARG ...)
|
(define-macro (stacker-module-begin ARG ...)
|
||||||
#'(#%module-begin
|
#'(#%module-begin
|
||||||
(define stack-result
|
(define stack-result
|
||||||
(for/fold ([stack empty])
|
(for/fold ([stack empty])
|
||||||
([arg (in-list (list STACK-ARG ...))])
|
([arg (in-list (list ARG ...))])
|
||||||
(push arg stack)))
|
(push arg stack)))
|
||||||
(display (first stack-result))))
|
(display (first stack-result))))
|
||||||
|
|
||||||
(define (push arg stack)
|
(define (push arg stack)
|
||||||
(cond
|
(if (number? arg)
|
||||||
[(number? arg) (cons arg stack)]
|
(cons arg stack)
|
||||||
[else
|
(cons (arg (first stack) (second stack)) (drop stack 2))))
|
||||||
(define result (arg (first stack) (second stack)))
|
|
||||||
(cons result (drop stack 2))]))
|
|
||||||
|
|
||||||
(provide + *)
|
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(require rackunit)
|
(require rackunit)
|
||||||
|
@ -1,24 +1,22 @@
|
|||||||
#lang br/quicklang
|
#lang br/quicklang
|
||||||
#:read-syntax stacker-read-syntax
|
(provide read-syntax (rename-out [stacker-module-begin #%module-begin]) + *)
|
||||||
#:#%module-begin stacker-module-begin
|
|
||||||
|
|
||||||
(define (stacker-read-syntax src-path in-port)
|
(define (read-syntax path port)
|
||||||
(strip-context
|
(strip-context
|
||||||
#`(module stacker3-mod br/demo/stacker3
|
#`(module stacker3-mod br/demo/stacker3
|
||||||
#,@(port->list read in-port))))
|
#,@(port->list read port))))
|
||||||
|
|
||||||
(define-macro (stacker-module-begin STACK-ARG ...)
|
(define-macro (stacker-module-begin ARG ...)
|
||||||
#'(#%module-begin
|
#'(#%module-begin
|
||||||
(display
|
(display (first
|
||||||
(first
|
(foldl
|
||||||
(foldl (λ(arg stack)
|
(λ(x xs)
|
||||||
(if (number? arg)
|
(if (number? x)
|
||||||
(cons arg stack)
|
(cons x xs)
|
||||||
(cons (arg (car stack) (cadr stack)) (cddr stack))))
|
(cons (x (car xs) (cadr xs)) (cddr xs))))
|
||||||
null (list STACK-ARG ...))))))
|
null (list ARG ...))))))
|
||||||
|
|
||||||
(provide + *)
|
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(require rackunit)
|
(require rackunit)
|
||||||
(check-equal? (with-output-to-string (λ () (dynamic-require "stacker2-test.rkt" #f))) "36"))
|
(check-equal? (with-output-to-string (λ () (dynamic-require "stacker3-test.rkt" #f))) "36"))
|
Loading…
Reference in New Issue