Subject: Re: dividing lists...tokenize
From: rpw3@rpw3.org (Rob Warnock)
Date: Mon, 27 Feb 2006 03:37:44 -0600
Newsgroups: comp.lang.lisp
Message-ID: <idadnYaZgpn1VZ_ZnZ2dnUVZ_sKdnZ2d@speakeasy.net>
Geoffrey King  <lordergeoffrey@optushome.com.au> wrote:
+---------------
| My (newbie) go at this is:
| (defun tokenize (token seq &optional result) ...)
| ...
| (tokenize 'A '(1 2 3 A 5 6 A 8 A 10 11))
| ((1 2 3) (5 6) (8) (10 11))
| 
| (tokenize 'A '(1 A))
| ((1))
| 
| (tokenize 'A '(A 1))
| ((1))
| 
| (tokenize 'A '(1 2 3))
| ((1 2 3))
+---------------

Also see <http://www.cliki.net/SPLIT-SEQUENCE>, which can be used
in similar ways, though by default it indicates the results slightly
differently [including a second return value for the index where
processing stopped]:

    > (require :split-sequence)

    ; Loading #p"/u/lisp/contrib/cclan/split-sequence/split-sequence.x86f".
    T
    > (use-package :split-sequence)

    T
    > (split-sequence 'A '(1 2 3 A 5 6 A 8 A 10 11))

    ((1 2 3) (5 6) (8) (10 11))
    11
    > (split-sequence 'A '(1 A))

    ((1) NIL)
    2
    > (split-sequence 'A '(A 1))

    (NIL (1))
    2
    > (split-sequence 'A '(1 2 3))

    ((1 2 3))
    3
    > 

To get the same results as yours in the 2nd & 3rd test case,
one would use the ":REMOVE-EMPTY-SUBSEQS T" option:

    > (split-sequence 'A '(1 A) :remove-empty-subseqs t)

    ((1))
    2
    > (split-sequence 'A '(A 1) :remove-empty-subseqs t)

    ((1))
    2
    > 


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607