You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
905 B
Racket
36 lines
905 B
Racket
8 years ago
|
#lang br/quicklang
|
||
9 years ago
|
|
||
8 years ago
|
(define (read-syntax path port)
|
||
|
(define args (port->lines port))
|
||
8 years ago
|
(define handle-datums (format-datums '(handle ~a) args))
|
||
8 years ago
|
(define module-datum `(module stacker-mod stacker-demo/stacker
|
||
8 years ago
|
,@handle-datums))
|
||
8 years ago
|
(datum->syntax #f module-datum))
|
||
8 years ago
|
(provide read-syntax)
|
||
9 years ago
|
|
||
8 years ago
|
(define-macro (stacker-module-begin HANDLE-EXPR ...)
|
||
9 years ago
|
#'(#%module-begin
|
||
8 years ago
|
HANDLE-EXPR ...
|
||
|
(display (first stack))))
|
||
8 years ago
|
(provide (rename-out [stacker-module-begin #%module-begin]))
|
||
9 years ago
|
|
||
|
(define stack empty)
|
||
|
|
||
8 years ago
|
(define (pop-stack!)
|
||
|
(define item (first stack))
|
||
|
(set! stack (rest stack))
|
||
|
item)
|
||
|
|
||
|
(define (push-stack! item)
|
||
|
(set! stack (cons item stack)))
|
||
|
|
||
8 years ago
|
(define (handle [arg #f])
|
||
8 years ago
|
(cond
|
||
8 years ago
|
[(number? arg) (push-stack! arg)]
|
||
8 years ago
|
[(or (equal? * arg) (equal? + arg))
|
||
8 years ago
|
(define op-result (arg (pop-stack!) (pop-stack!)))
|
||
|
(push-stack! op-result)]))
|
||
8 years ago
|
(provide handle)
|
||
9 years ago
|
|
||
8 years ago
|
(provide + *)
|