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.
beautiful-racket/beautiful-racket-demo/stacker-demo/stacker.rkt

36 lines
905 B
Racket

#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))
(define module-datum `(module stacker-mod stacker-demo/stacker
8 years ago
,@handle-datums))
9 years ago
(datum->syntax #f module-datum))
(provide read-syntax)
(define-macro (stacker-module-begin HANDLE-EXPR ...)
#'(#%module-begin
HANDLE-EXPR ...
(display (first stack))))
(provide (rename-out [stacker-module-begin #%module-begin]))
(define stack empty)
9 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])
(cond
9 years ago
[(number? arg) (push-stack! arg)]
[(or (equal? * arg) (equal? + arg))
9 years ago
(define op-result (arg (pop-stack!) (pop-stack!)))
(push-stack! op-result)]))
(provide handle)
(provide + *)