https://stackoverflow.com/questions/49136510/list-all-leaves-of-huffman-tree/49137936#49137936
On the "fundamentals" level, in Scheme we write functions to either construct and return a value, or for their side-effects – meaning, when they do something while we ignore their returned value.
What can a function do? A list can be altered in-place with set-car!
, and grown ⁄ shrunk with set-cdr!
, as an example. append
does neither. It constructs new value, new list, from its arguments. But then we have to use this new value somehow, have to return it from our function. Just writing (append a b)
does nothing, if it's not (in) the last expression in a function.
Your code is written in imperative style, and even that with the order of operations jumbled up. You meant