Added cond function to Userlib

Added the cond function to Userlib, also added the associated tests
and documentation.
This commit is contained in:
dariof4 2023-06-13 00:18:11 +02:00
parent fb724ccee4
commit bd23198009
3 changed files with 68 additions and 1 deletions

View file

@ -55,6 +55,36 @@
(adder (lambda (x y) (add x y))))
(eq? (reduce adder list) (add 1 2 3)))))
('cond evaluates the first branch that returns true'
(quote
(let ((switch-one false)
(switch-two false)
(switch-three false))
(cond (q
((false (toggle switch-one))
(true (toggle switch-two))
(true (toggle switch-three)))))
(and (not switch-one) switch-two (not switch-three)))))
('cond doesnt do anything if all the branches are false'
(quote
(let ((switch-one false)
(switch-two false)
(switch-three false))
(cond (q
((false (toggle switch-one))
(false (toggle switch-two))
(false (toggle switch-three)))))
(and (not switch-one) (not switch-two) (not switch-three)))))
('cond returns the result of the branch that is evaluated'
(quote
(let ((variable false))
(set (q variable)
(cond (q
((true true)))))
variable)))
('contains? finds elem in list'
(quote
(contains? (1 2 3) 1)))