DO

While DOLIST and DOTIMES are convenient and easy to use, they aren’t flexible enough to use for all loops. For instance, what if you want to step multiple variables in parallel?

(do (variable-definition*)
    (end-test-form result-form*)
  statement*)

— Practical Common Lisp

— Peter Seibel

.

(defun split-if (fn lst)
  (let ((acc nil))
    (do ((src lst (cdr src)))
        ((or (null src) (funcall fn (car src)))
         (values (nreverse acc) src))
      (push (car src) acc))))


>(split-if #'(lambda (x) (> x 4)) '(1 2 3 4 5 6 7 8 9 10))

(1 2 3 4)
(5 6 7 8 9 10)

— p.50

— On Lisp

— Paul Graham

.

Exercise 4.5

Implement the function split-if without using the macro do.

— Me@2019-01-30 09:58:30 PM

.

.

2019.01.30 Wednesday ACHK