Last active
June 21, 2018 19:44
-
-
Save emdeesee/9bf69f2482dab10d3186e2610f124763 to your computer and use it in GitHub Desktop.
Return the sequence created by calling fn on each element of seq, until the result is NIL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun while (fn seq) | |
"Evaluates to the sequence that results from calling fn on each element of seq, until the result is NIL" | |
(labels ((aux (seq acc) | |
(if (null seq) acc | |
(let ((val (funcall fn (first seq)))) | |
(if val | |
(aux (rest seq) (cons val acc)) | |
acc))))) | |
(aux seq nil))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not sure if this is utilities worthy, but I want to save it just in case.