| Paste number 50654: | span |
| Pasted by: | jmbr |
| 8 months, 3 weeks ago | |
| #lispcafe | Context in IRC logs | |
| Paste contents: |
| (defun span (predicate list) "Splits LIST into two lists (returned as VALUES) such that elements in the first list are taken from the head of LIST while PREDICATE is satisfied, and elements in the second list are the remaining elements from LIST once PREDICATE is not satisfied." (do* ((xs list (rest xs)) (x (first xs) (first xs)) (ys (cons x nil) (cons x ys))) ((or (null xs) (not (funcall predicate x))) (values (nreverse (rest ys)) xs)))) |
Annotations for this paste:
| Annotation number 1: | Added reference to previous implementation |
| Pasted by: | jmbr |
| 8 months, 3 weeks ago | |
| Context in IRC logs | |
| Paste contents: |
| See also http://paste.lisp.org/display/48648 |
| Annotation number 2: | Final version |
| Pasted by: | jmbr |
| 8 months, 3 weeks ago | |
| Context in IRC logs | |
| Paste contents: |
| (defun span (predicate list) "Splits LIST into two lists (returned as VALUES) such that elements in the first list are taken from the head of LIST while PREDICATE is satisfied, and elements in the second list are the remaining elements from LIST once PREDICATE is not satisfied." (do ((list list (rest list)) (xs nil (cons (first list) xs))) ((or (null list) (not (funcall predicate (first list)))) (values (nreverse xs) list)))) |