Re: dividing lists...tokenize
- From: Geoffrey King <lordergeoffrey@xxxxxxxxxxxxxxxx>
- Date: Mon, 27 Feb 2006 19:07:42 +1000
My (newbie) go at this is:
(defun tokenize (token seq &optional result)
(let ((p (position token seq)))
(cond
((null seq)
result)
((null p)
(append result (list seq)))
(T
(tokenize token
(subseq seq (1+ p))
(append result
(if (null (subseq seq 0 p))
nil
(list (subseq seq 0 p)))))))))
(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))
Don't really like the two (subseq seq 0 p). Is that evaluated twice?
rich wrote:
hi,.
can anybody help m ewith dividing the given list into 3 parts as :
the list i have is
(1 3 4 5 0 6 A 2 4 7 8)
I have to divide this in 3 list as (1 3 4 5 0 6) (A) (2 4 78)
i.e lists to the left and right of symbol A
thanks.
- Follow-Ups:
- Re: dividing lists...tokenize
- From: Rob Warnock
- Re: dividing lists...tokenize
- References:
- dividing lists
- From: rich
- dividing lists
- Prev by Date: Re: lisp idiom for processing each line in a file?
- Next by Date: Re: Performance of generic functions
- Previous by thread: Re: dividing lists
- Next by thread: Re: dividing lists...tokenize
- Index(es):
Relevant Pages
|
|