From 7188d4159117c8d83080adf090bbda40f2b79b93 Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Sun, 14 Jan 2024 00:36:19 +0100 Subject: [PATCH] add missing test for dynamic scope --- tests/dynamic.scm | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/dynamic.scm diff --git a/tests/dynamic.scm b/tests/dynamic.scm new file mode 100644 index 000000000..ce43b41bc --- /dev/null +++ b/tests/dynamic.scm @@ -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)))