Say you want append these list of lists and output a single list that contains all the numbers
(append-lists (list (list 1 2)
(list 4 5)
(list 10 19))) => (list 1 2 4 5 10 19)
If using trivial append, i can do this,
((define (append-lists llon)
(cond
[(empty? llon) empty]
[(cons? llon) (cons (first llon)
(append-lists (rest llon)))]))
But how to get the same output without using append just by recursion?
This is a special case of flattening. Some Scheme implementation feature a build-in
flatten
procedure; if not, a general flattening algorithm is :Testing: