Skip to content

Commit

Permalink
Fix make_leaf_set function call argument (#1076)
Browse files Browse the repository at this point in the history
make_leaf_set (in line 776) "takes a list of symbol-frequency pairs such as list(list("A", 4), list("B", 2), list("C", 1), list("D", 1))" and not a list of leafs. 

Because the argument is a list of leafs, the resulting list will look like this: 

[ ["leaf", ["leaf", ["A", null]]],
[ ["leaf", ["leaf", ["B", null]]],
[["leaf", ["leaf", ["C", null]]], [["leaf", ["leaf", ["D", null]]], null]]]]

head(first_pair) (in line 766) expects a list with the first item being the symbol and the second item the frequency.
  • Loading branch information
TomSoerr authored Feb 20, 2025
1 parent 2390a6e commit 6e2c814
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions xml/chapter2/section3/subsection4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -766,16 +766,16 @@ function make_leaf_set(pairs) {
<SNIPPET HIDE="yes">
<NAME>make_leaf_set_example</NAME>
<JAVASCRIPT>
make_leaf_set( list( make_leaf("A", 4),
make_leaf("B", 2),
make_leaf("C", 1),
make_leaf("D", 1) ) );
make_leaf_set( list( list("A", 4),
list("B", 2),
list("C", 1),
list("D", 1) ) );
</JAVASCRIPT>
<JAVASCRIPT_TEST>
head(make_leaf_set( list( make_leaf("A", 4),
make_leaf("B", 2),
make_leaf("C", 1),
make_leaf("D", 1) ) ) );
head(make_leaf_set( list( list("A", 4),
list("B", 2),
list("C", 1),
list("D", 1) ) ) );
</JAVASCRIPT_TEST>
</SNIPPET>
</TEXT>
Expand Down

0 comments on commit 6e2c814

Please sign in to comment.