2020-10-20 22:11:57 -04:00
|
|
|
(let (
|
|
|
|
|
check_and_erase (lambda (x type)
|
|
|
|
|
(let (xe (x)
|
2020-10-20 22:59:21 -04:00
|
|
|
xt (meta xe))
|
|
|
|
|
(if (= type xt) xe (println "\n\nType error, expected" type "but got" xt "\n\n")))
|
2020-10-20 22:11:57 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
add_one_impl (lambda (x) (+ x 1))
|
|
|
|
|
|
2020-10-20 22:59:21 -04:00
|
|
|
stlc [
|
2020-10-20 22:11:57 -04:00
|
|
|
|
2020-10-20 22:59:21 -04:00
|
|
|
[ 'WS [ "( | |
|
2020-10-20 22:11:57 -04:00
|
|
|
|(;[ -~]*
|
2020-10-20 22:59:21 -04:00
|
|
|
))+"] (lambda (x) nil)]
|
2020-10-20 22:11:57 -04:00
|
|
|
|
2020-10-20 22:59:21 -04:00
|
|
|
[ 'stlc_expr '("-?[0-9]+") (lambda (x) (lambda () (with-meta (read-string x) 'int))) ]
|
|
|
|
|
[ 'stlc_expr '("plus") (lambda (x) (lambda () (with-meta + '(int int int)))) ]
|
|
|
|
|
[ 'stlc_expr '("call" WS stlc_expr WS stlc_expr WS stlc_expr)
|
|
|
|
|
(lambda (_ _ c _ a _ b) (lambda ()
|
|
|
|
|
(let (
|
|
|
|
|
ae (check_and_erase a 'int)
|
|
|
|
|
be (check_and_erase b 'int)
|
|
|
|
|
ce (check_and_erase c '(int int int))
|
|
|
|
|
)
|
|
|
|
|
(with-meta [ce ae be] 'int)
|
|
|
|
|
))) ]
|
|
|
|
|
[ 'stlc '(stlc_expr) (lambda (x) (check_and_erase x 'int)) ]
|
|
|
|
|
]
|
2020-10-20 22:11:57 -04:00
|
|
|
|
2020-10-20 22:59:21 -04:00
|
|
|
our_expr "call plus 13 20"
|
2020-10-20 22:11:57 -04:00
|
|
|
)
|
2020-10-20 22:59:21 -04:00
|
|
|
(println "\n\nExpr evaluates to" (eval (read-string our_expr stlc 'stlc)) "\n")
|
2020-10-20 22:11:57 -04:00
|
|
|
)
|