Skip to content

Instantly share code, notes, and snippets.

@eklitzke
Created July 14, 2009 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eklitzke/146723 to your computer and use it in GitHub Desktop.
Save eklitzke/146723 to your computer and use it in GitHub Desktop.
(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