I'm stuck trying to write a function that will split a list in multiple
lists.. e.g. (splitlist '( A B C D E))
suppose C is a delimiter atom that I pick, the result should be three
lists (A B) (C) (D E)
I know this is probably very trival, but I'm just started learning
lisp. Can someone please show me how to do this properly.
Thanks
Sent via Deja.com http://www.deja.com/
Before you buy.
In article <············@nnrp1.deja.com>,
jj3000 <·········@my-deja.com> wrote:
>I'm stuck trying to write a function that will split a list in multiple
>lists.. e.g. (splitlist '( A B C D E))
>suppose C is a delimiter atom that I pick, the result should be three
>lists (A B) (C) (D E)
>
>I know this is probably very trival, but I'm just started learning
>lisp. Can someone please show me how to do this properly.
(defun splitlist (delimiter list)
(let ((pos (position delimiter list)))
(when pos
(list (subseq list 0 pos) (list delimiter)
(subseq list (1+ pos))))))
(defun splitlist (delimiter list)
(let ((tail (member delimiter list)))
(when tail
(list (ldiff list tail)
(list delimiter)
(cdr tail)))))
--
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.