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)
7 years ago
(define src-lines (port->lines port))
(define src-datums (format-datums '(handle ~a) src-lines))
(define module-datum `(module stacker-mod stacker-demo/stacker
7 years ago
,@src-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!)
8 years ago
(define arg (first stack))
9 years ago
(set! stack (rest stack))
8 years ago
arg)
9 years ago
8 years ago
(define (push-stack! arg)
(set! stack (cons arg stack)))
9 years ago
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 + *)