Paste number 50654: span

Index of paste annotations: 1 | 2

Paste number 50654: span
Pasted by: jmbr
8 months, 3 weeks ago
#lispcafe | Context in IRC logs
Paste contents:
Raw Source | XML | Display As
(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:
Raw Source | Display As
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:
Raw Source | Display As
(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)
)
)
)

Colorize as:
Show Line Numbers
Index of paste annotations: 1 | 2

Ads absolutely not by Google

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.