!(load "quasi.lurk") !(load "compile.lurk") !(assert-eq 1 (compile-closure 1 '(b) '() '((a . 1)))) !(assert-eq 1 (compile-closure 'a '(b) '() '((a . 1)))) !(assert-eq '(+ 1 b) (compile-closure '(+ a b) '(b) '() '((a . 1)))) !(assert-eq '(+ 1 b) (compile-closure '(+ a b) '(b) '() '((a . 1) (b . 2)))) !(assert-eq '(lambda (a) (+ a b)) (compile-closure '(lambda (a) (+ a b)) '(b) '() '((a . 1)))) !(assert-eq '(let ((a (+ 1 b))) (+ a b)) (compile-closure '(let ((a (+ c b))) (+ a b)) '(b) '() '((c . 1)))) !(assert-eq '(+ 1 b) (compile-closure '(+ a b) '(b) '() ;;(current-ram) TODO: RAM is not an exp '((a . 1)))) !(assert-eq '(+ 1 b) (let ((a 1)) (compile-closure '(+ a b) '(b) '() (current-env)))) !(assert-eq '(+ (f 1) b) (let ((a 1) ;;(f (lambda (x) x)) ) (compile-closure '(+ (f a) b) '(b) '() (current-env)))) !(assert-eq '(+ (f 1) b) (letrec ((a 1) ;;(f (lambda (x) x)) ) (compile-closure '(+ (f a) b) '(b) '() (current-env)))) !(assert-eq 1 ((lambda (x) x) 1)) !(assert-eq 1 ((compile (lambda (x) x)) 1)) !(assert-eq 12 (let ((a 1) (f (lambda (b) (+ a b)))) (* (f 2) (f 3)))) !(assert-eq 12 (let ((a 1) (f (lambda (b) (+ a b))) (f (compile f))) (* (f 2) (f 3)))) !(assert-eq 12 (letrec ((a 1) (f (lambda (b) (+ a b))) (fc (compile f))) (* (fc 2) (fc 3)))) (define foo 1) (define foofun (compile (lambda (x) (+ x foo)))) !(assert-eq 3 (foofun 2)) ;; re-defining foo does not change the inlined foo value in foofun (define foo 2) !(assert-eq 4 (foofun 3)) !(assert-eq 1 (let ((bar (lambda (y) y))) (let ((f (lambda (z) (bar 1)))) (let ((fc (compile f))) (fc '(6 2)))))) !(assert-eq 1 (let ((bar (lambda (y z) y))) (let ((f (lambda (x) (bar 1 2)))) (let ((fc (compile f))) (fc '(6 3)))))) !(assert-eq '(6 1) (let ((bar (lambda (y) y))) (let ((f (lambda (x) (bar x)))) (let ((fc (compile f))) (fc '(6 1)))))) !(assert-eq '(6 1) (let ((bar (lambda (x) x))) (let ((f (lambda (x) (bar x)))) (let ((fc (compile f))) (fc '(6 1)))))) !(assert-eq 3 ;; this example just respects the semantics of Lurk, ;; in which a built-in like + take precedence over the lexical environment (let ((+ (lambda (y z) (list y z)))) (let ((f (lambda (x) (+ 1 2)))) (let ((fc (compile f))) (fc '(6 3)))))) !(assert-eq 6 ;; ditto for built-in car (let ((car (lambda (y) y))) (let ((f (lambda (x) (car x)))) (let ((fc (compile f))) (fc '(6 1)))))) !(assert-eq '(a b c) (let ((a (lambda (b c) b))) (let ((f (lambda (x) '(a b c)))) (let ((fc (compile f))) (fc 1)))))