list contains implemented

This commit is contained in:
Ava Apples Affine 2023-03-20 22:03:10 -07:00
parent da0709c4db
commit b638918a89
Signed by: affine
GPG key ID: 3A4645B8CF806069
7 changed files with 36 additions and 9 deletions

View file

@ -85,3 +85,18 @@ this will continue iuntil the list is exhausted.'
(set (q result) (func result current))
(set (q list-iter) (pop remaining)))))
result))
(def contains?
'Takes two arguments: a list and an element.
Returns true if the list contains the element.'
(list elem)
(let ((found false)
(list-iter (pop list)))
(while (and (gt? (len list-iter) 1)
(not found))
(let ((current (car list-iter))
(remaining (cdr list-iter)))
(if (eq? current elem)
(set (q found) true)
(set (q list-iter) (pop remaining)))))
found))