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
|
||||
#:read-syntax stacker-read-syntax
|
||||
#:#%module-begin stacker-module-begin
|
||||
(provide read-syntax
|
||||
(rename-out [stacker-module-begin #%module-begin])
|
||||
+ *)
|
||||
|
||||
(define (stacker-read-syntax src-path in-port)
|
||||
(define stack-args (port->list read in-port))
|
||||
(with-pattern ([(STACK-ARG ...) stack-args])
|
||||
(strip-identifier-bindings
|
||||
#'(module stacker2-mod br/demo/stacker2
|
||||
STACK-ARG ...))))
|
||||
(define (read-syntax src-path in-port)
|
||||
(define args (port->list read in-port))
|
||||
(define module-datum `(module stacker2-mod br/demo/stacker2
|
||||
,@args))
|
||||
(datum->syntax #f module-datum))
|
||||
|
||||
(define-macro (stacker-module-begin STACK-ARG ...)
|
||||
(define-macro (stacker-module-begin ARG ...)
|
||||
#'(#%module-begin
|
||||
(define stack-result
|
||||
(for/fold ([stack empty])
|
||||
([arg (in-list (list STACK-ARG ...))])
|
||||
([arg (in-list (list ARG ...))])
|
||||
(push arg stack)))
|
||||
(display (first stack-result))))
|
||||
|
||||
(define (push arg stack)
|
||||
(cond
|
||||
[(number? arg) (cons arg stack)]
|
||||
[else
|
||||
(define result (arg (first stack) (second stack)))
|
||||
(cons result (drop stack 2))]))
|
||||
|
||||
(provide + *)
|
||||
(if (number? arg)
|
||||
(cons arg stack)
|
||||
(cons (arg (first stack) (second stack)) (drop stack 2))))
|
||||
|
||||
(module+ test
|
||||
(require rackunit)
|
||||
|
@ -1,24 +1,22 @@
|
||||
#lang br/quicklang
|
||||
#:read-syntax stacker-read-syntax
|
||||
#:#%module-begin stacker-module-begin
|
||||
(provide read-syntax (rename-out [stacker-module-begin #%module-begin]) + *)
|
||||
|
||||
(define (stacker-read-syntax src-path in-port)
|
||||
(define (read-syntax path port)
|
||||
(strip-context
|
||||
#`(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
|
||||
(display
|
||||
(first
|
||||
(foldl (λ(arg stack)
|
||||
(if (number? arg)
|
||||
(cons arg stack)
|
||||
(cons (arg (car stack) (cadr stack)) (cddr stack))))
|
||||
null (list STACK-ARG ...))))))
|
||||
(display (first
|
||||
(foldl
|
||||
(λ(x xs)
|
||||
(if (number? x)
|
||||
(cons x xs)
|
||||
(cons (x (car xs) (cadr xs)) (cddr xs))))
|
||||
null (list ARG ...))))))
|
||||
|
||||
(provide + *)
|
||||
|
||||
(module+ test
|
||||
(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