(defun white-space-p (c)
  "Returns T if character C consists of a space, tabulator or newline,
NIL otherwise."
  (declare (type character c))
  (member c '(#\Space #\Tab #\Newline)))

(defun split-sequence (sequence &key (start 0) (end nil) (max nil)
		       (separator #'white-space-p))
  "Returns an array containing the components from SEQUENCE as well as
the number of components returned.
Begins looking for components at offset START (default 0),
stops before END (default NIL for end of sequence)
and will return a maximum of MAX components (default NIL for no limit).
The SEPARATOR function should return T for elements matching the wanted
separators, or NIL (defaults to #'WHITE-SPACE-P, for use with strings)."
  (declare (type fixnum start)
	   (type (or null fixnum) end max))
  (let ((array (make-array (or max 16)
                           :fill-pointer 0
                           :adjustable t))
	(array-len 0)
	(s start))
    (declare (type fixnum array-len)
	     (type (or null fixnum s)))
    (flet ((add-component (c)
	     (unless (vector-push c array)
	       (adjust-array array (* 2 (array-dimension array 0)))
	       (vector-push c array))))
      (unless end
	(setf end (length sequence)))
      (when max
	(decf max))
      (loop
	 for i of-type fixnum from s below end
	 until (and max (< max array-len))
	 while (setf s (position-if-not separator sequence :start i))
	 do
	   (setf i (or (position-if separator sequence :start s)
		       end))
	   (add-component (subseq sequence s i))
	   (incf array-len)))
    (values array array-len)))
