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