I am trying to split and return a number of sublists at a given element 0; call it (split-Elem list).
(split-Elem '(2 3 0 6 5 1 0 1 0)) => ((2 3) (6 5 1) (1)).
Here is what I have so far:
(define (split-Elem data)
(if(null? data) '()
( let* ((head (car data))
(tail (cdr data)))
(if(= head 0) (split-Elem tail)
( let *((tail1 (car tail)))
(if(= tail1 0) (append (list(cons head '())) (split-Elem (cdr tail)))
(append (list(cons head tail1)) (split-Elem (cdr tail))
)))))))
What was worse, using this code I get a very wired answer:
(split-Elem '(2 3 0 6 5 1 0 1 0)) => ((2.3) (6.5) (1) (1)).
I have no idea about the error and appreciate any help I could get. Many Thanks.

New Topic/Question
Reply


MultiQuote




|