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.
31 lines
990 B
Racket
31 lines
990 B
Racket
#lang br/quicklang
|
|
|
|
(define (read-syntax path port)
|
|
(define args (port->lines port))
|
|
(define arg-datums (format-datums '~a args))
|
|
(define module-datum `(module stacker-mod br/demo/funstacker
|
|
(handle-args ,@arg-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 + *)
|
|
|
|
(module+ test
|
|
(require rackunit)
|
|
(check-equal? (with-output-to-string (λ () (dynamic-require "funstacker-test.rkt" #f))) "36")) |