Re: split-sequence



In article <1135874537.504798.124120@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
justinhj <justinhj@xxxxxxxxx> wrote:
> The original was by Frank Bus I think. I've changed it so it strips
> leading spaces each item (the original did that too, but not the last
> item in the list)
>
> (defun split(string delimiter)
> (let ((start (search delimiter string)))
> (if (not start)
> (if (= 0 (length string))
> nil
> (list (string-trim '(#\Space) string)))
> (let ((value (string-trim '(#\Space) (subseq string 0 start)))
> (rest (subseq string (+ start (length delimiter)))))
> (if (= 0 (length value))
> (split rest delimiter)
> (cons value (split rest delimiter)))))))

More loopy, less consy, and will work on any kind of sequence if you
don't provide the :string-trim keyword:

(defun split-sequence-subsequence (subsequence sequence &key string-trim)
(loop for last = 0 then (+ pos (length subsequence))
for pos = (search subsequence sequence :start2 last)
for subseq = (subseq sequence last (or pos (length sequence)))
when string-trim do (setf subseq (string-trim string-trim subseq))
unless (zerop (length subseq)) collect subseq
while pos))

-bcd
--
*** Brian Downing <bdowning at lavos dot net>
.



Relevant Pages

  • Black writers
    ... of black writers in comic books, strips, and pulp fiction between 1920 ... Prev by Date: ...
    (soc.culture.african.american.moderated)
  • Re: Morning Watch Smoke; October 25, 2005
    ... it's a fantastic bowl size for this ... blend, I cut two strips in half, folded them and stuffed them:) ... Prev by Date: ...
    (alt.smokers.pipes)
  • Re: Whats good to fumigate a basement?
    ... lay out strips of tape. ... Prev by Date: ...
    (alt.home.repair)
  • Re: By the way DRUSILLA is back
    ... Dave Van Domelen, now definitely figuring this is a technical issue, not ... a "Brooke got behind on strips" issue. ... Prev by Date: ...
    (rec.arts.comics.strips)
  • Re: 3rd Party Test Strips
    ... same with strips too.. ... |>damn and here i'm the idiot for giving away ... Newsgroups ... Prev by Date: ...
    (alt.support.diabetes)