(define (flatten sequence)
(cond ((null? sequence) (list))
((list? (car sequence))
(append (flatten (car sequence))
(flatten (cdr sequence))))
(else
(cons (car sequence)
(flatten (cdr sequence))))))
I pretty-printed it (inserted some new lines and backed off the code to show its structure), and also replaced it '()with (list)(which has the same meaning) to prevent the code from being allocated incorrectly.
+1 what is in the way? I would appreciate it if you could explain other keywords as well. thanks
"cons-ing", cons. (cons <expression> <list>), <expression> - , <list> - , , cons <list> <expression>, . , (cons 1 (list 2 3 4)) (list 1 2 3 4). , (list 1 2 3 4) - (cons 1 (cons 2 (cons 3 (cons 4 '() )))).
, , car cdr. (car <list>) first head <list> (cdr <list>), rest tail <list>. , (car (list 1 2 3 4)) 1, (cdr (list 1 2 3 4)) (list 2 3 4).
, .