Added cond function to Userlib
Added the cond function to Userlib, also added the associated tests and documentation.
This commit is contained in:
parent
fb724ccee4
commit
bd23198009
3 changed files with 68 additions and 1 deletions
|
|
@ -84,6 +84,20 @@ this will continue iuntil the list is exhausted.'
|
|||
(set (q list-iter) (pop remaining)))))
|
||||
result))
|
||||
|
||||
(def cond
|
||||
'Takes one argument: a list of pairs consisting of a form returning a bool and a form to execute
|
||||
The function iterates over the list checking if the first form of a pair evaluates to true, in which
|
||||
case it will execute the second form of the pair, returning its result, and stop the loop.'
|
||||
(list)
|
||||
(let ((iter list))
|
||||
(while (gt? (len iter) 0)
|
||||
(let ((current (car iter))
|
||||
(remaining (pop iter)))
|
||||
(if (eval (car current))
|
||||
(car (pop ((set (q iter) ())
|
||||
(eval (cdr current)))))
|
||||
(set (q iter) (cdr remaining)))))))
|
||||
|
||||
(def contains?
|
||||
'Takes two arguments: a list and an element.
|
||||
Returns true if the list contains the element.'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue