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/funstacker-demo/funstacker.rkt

29 lines
892 B
Racket

#lang br/quicklang
8 years ago
(define (read-syntax path port)
7 years ago
(define src-lines (port->lines port))
(define src-datums (format-datums '~a src-lines))
(define module-datum `(module funstacker-mod "funstacker.rkt"
7 years ago
(handle-args ,@src-datums)))
(datum->syntax #f module-datum))
8 years ago
(provide read-syntax)
(define-macro (funstacker-module-begin HANDLE-ARGS-EXPR)
#'(#%module-begin
8 years ago
(display (first HANDLE-ARGS-EXPR))))
(provide (rename-out [funstacker-module-begin #%module-begin]))
8 years ago
(define (handle-args . args)
(for/fold ([stack-acc empty])
7 years ago
([arg (in-list args)]
#:unless (void? arg))
8 years ago
(cond
[(number? arg) (cons arg stack-acc)]
8 years ago
[(or (equal? * arg) (equal? + arg))
(define op-result
(arg (first stack-acc) (second stack-acc)))
(cons op-result (drop stack-acc 2))])))
8 years ago
(provide handle-args)
(provide + *)