-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunstacker.rkt
27 lines (23 loc) · 862 Bytes
/
funstacker.rkt
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
#lang br/quicklang
(define (read-syntax path port)
(define args (port->lines port))
(define handle-datums (format-datums '~a args))
(define module-datum `(module funstacker-mod "funstacker.rkt"
(handle-args ,@handle-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 (filter-not void? args)])
(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 + *)