Skip to content

Instantly share code, notes, and snippets.

@emdeesee
Last active June 21, 2018 19:44
Show Gist options
  • Save emdeesee/9bf69f2482dab10d3186e2610f124763 to your computer and use it in GitHub Desktop.
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
(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)))
@emdeesee
Copy link
Author

I'm not sure if this is utilities worthy, but I want to save it just in case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment