This is my Huffman coding that returns an empty list. My purpose was to make it add all the pairs to listenr1
but it seams to only return an empty list. I'm not sure why it's not appending, but I think I have misunderstood a fundamental part of Scheme programming. I do not want to use append*
. I think the appending might be wrong, but I'm not exactly sure why. Is there a way to replace listenr1
each time it appends maybe?
(define (huffman-leafs tree)
(let ((listenr1 '()))
(define (iterator currentbranch)
(let ((left (left-branch currentbranch))
(right (right-branch currentbranch)))
(if (leaf? left)
(list (symbols left) (weight left))
(append listenr1 (iterator left)))
(if (leaf? right)
(list (symbols right) (weight right))
(append listenr1 (iterator right)))))
(iterator tree)
listenr1))
(huffman-leafs mytree)