I'm new in scheme programming and I'm learning basic algorithms, like how to define map, append and so on.
But there is an algorithm for which I can't find an implementation. I speak about transforming an M-dimensional list into one dimension. I tried to define it by myself, but without success.
What exactly I want:
'(a b c (d (e)) (g f h)) => '(a b c d e g f h)
There are a couple of ways to flatten a list. First, a straightforward solution using only primitive list procedures:
This other solution uses the
map
higher-order procedure andapply
(as suggested by John Clements):And finally, as has been mentioned in the comments, the built-in
flatten
procedure found in some Scheme implementations like Racket (I don't know if it's available in bigloo):