Re: dividing lists...tokenize
- From: rpw3@xxxxxxxx (Rob Warnock)
- Date: Mon, 27 Feb 2006 03:37:44 -0600
Geoffrey King <lordergeoffrey@xxxxxxxxxxxxxxxx> 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@xxxxxxxx>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607
.
- References:
- dividing lists
- From: rich
- Re: dividing lists...tokenize
- From: Geoffrey King
- dividing lists
- Prev by Date: Re: Performance of generic functions
- Next by Date: Re: eval use ?
- Previous by thread: Re: dividing lists...tokenize
- Index(es):