Reputation: 35
I keep getting the error in DrRacket: define: expected only one expression for the function body, but found 1 extra part in:
(cond ((empty? (rest a-list) (first a-list))) (huffman-tree (insert-node (newn (first a-list) (first (rest a-list)) (rest (rest a-list))))))
This is my Code:
(define (huffman-tree a-list)
(local(
(define (newn altn1 altn2)
(cond [(empty? altn2) altn1]
[else (make-node (node-frequency altn1) (node-frequency altn2))
(string-append (node-value alt n1) (node-value altn2)) altn1 altn2]))))
(cond [(empty? (rest a-list) (first a-list))]
(huffman-tree (insert-node (newn (first a-list)
(first (rest a-list)) (rest (rest a-list))))))
)
At the moment we just don´t know what we did wrong.
Upvotes: 1
Views: 451
Reputation: 235984
There are a couple of syntax errors in the code, and we can't test it because it references several helper functions that you didn't post, and we don't know the sample input and the expected output.
Some of the errors can be solved by simply fixing the formatting of your code (some parentheses were unbalanced!), I can help with that but I can't guarantee that your algorithm is correct for the previously mentioned reasons. See if this works:
(define (huffman-tree a-list)
(local [(define (newn altn1 altn2)
(cond [(empty? altn2) altn1]
[else (make-node (node-frequency altn1)
(node-frequency altn2))
(string-append (node-value altn1)
(node-value altn2)) altn1 altn2]))]
(cond [(empty? (rest a-list) (first a-list))]
(huffman-tree (insert-node
(newn (first a-list)
(first (rest a-list)) (rest (rest a-list))))))))
Upvotes: 1