Created
July 14, 2009 05:16
-
-
Save eklitzke/146723 to your computer and use it in GitHub Desktop.
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 my-span (p lst) | |
"Break the input list into two components -- the front part of | |
the list whose elements satisfy the predicate p, and the rest of | |
the list (at least the car of this list does not satisfy p)." | |
(let (span-front span-back) | |
(while (and lst (funcall p (car lst))) | |
(setq span-front (cons (car lst) span-front)) | |
(setq span-back (cdr lst)) | |
(setq lst (cdr lst)) | |
(setq span-front (nreverse span-front))) | |
(cons span-front span-back))) | |
(my-span (lambda (x) (< x 5)) '(1 2 3 4 5 6 7 8 9 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment