Implement loop/return forms

This commit is contained in:
2026-05-08 17:43:12 +03:00
parent aa0026fa45
commit aa7e371747
6 changed files with 201 additions and 37 deletions
+32
View File
@@ -0,0 +1,32 @@
;; vi:ft=lisp:sw=2:ts=2
;; loop, broken by (return)
(setq looped-loop (let (i 0)
(loop
(if (< i 10)
(setq i (+ i 1))
(return)
)
)
i
))
;; while, broken prematurely
(setq looped-while (let (i 0)
(while (< i 20)
(setq i (+ i 1))
(if (= i 10) (return))
)
i
))
;; while, broken by condition
(setq looped-while-full (let (i 0)
(while (< i 10)
(setq i (+ i 1))
)
i
))
;; All loops execute the same count of times
(assert (= looped-loop looped-while looped-while-full))