1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #lang br/quicklang (define (read-syntax path port) (define src-lines (port->lines port)) (define src-datums (format-datums '~a src-lines)) (define module-datum `(module funstacker-mod "funstacker.rkt" (handle-args ,@src-datums))) (datum->syntax #f module-datum)) (provide read-syntax) (define-macro (funstacker-module-begin HANDLE-ARGS-EXPR) #'(#%module-begin (display (first HANDLE-ARGS-EXPR)))) (provide (rename-out [funstacker-module-begin #%module-begin])) (define (handle-args . args) (for/fold ([stack-acc empty]) ([arg (in-list args)] #:unless (void? arg)) (cond [(number? arg) (cons arg stack-acc)] [(or (equal? * arg) (equal? + arg)) (define op-result (arg (first stack-acc) (second stack-acc))) (cons op-result (drop stack-acc 2))]))) (provide handle-args) (provide + *) |