Skip to content

Commit

Permalink
add missing unit tests file for dynamic scope
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jan 13, 2024
1 parent 3d0f5f5 commit b621b1b
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/dynamic.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
(define-macro (exec code)
(lips.evaluate code &(:use_dynamic true)))

(test "dynamic: let"
(lambda (t)
(t.is (exec (begin
(define (f)
(let ((y 10))
(+ x y)))
(let ((x 10))
(f))))
20)))

(test "dynamic: function parameters"
(lambda (t)
(t.is (exec (begin
(define (f y)
(+ x y))
(let ((x 10))
(f 10))))
20)))

(test "dynamic: set"
(lambda (t)
(t.is (exec (begin
(define (f)
(set! x (* x x)))
(let ((x 10))
(f)
x)))
100)))

;; https://www.reddit.com/r/lisp/comments/1943lg6/comment/khehb28/?context=3
(test "dynamic: stak"
(lambda (t)
(t.is
(exec (begin
(define (stak x y z)
(stak-aux))

(define (stak-aux)
(if (not (< y x))
z
(let
((x (let ((x (1- x))
(y y)
(z z))
(stak-aux)))
(y (let ((x (1- y))
(y z)
(z x))
(stak-aux)))
(z (let ((x (1- z))
(y x)
(z y))
(stak-aux))))
(stak-aux))))
(stak 18 12 6)))
7)))

0 comments on commit b621b1b

Please sign in to comment.