source-academy / sicp

XML sources of SICP and SICP JS, and support for generating Interactive SICP JS, PDF, e-book and comparison editions
https://sourceacademy.org/sicpjs
Creative Commons Attribution Share Alike 4.0 International
905 stars 120 forks source link

Missing Function Declarations in Solution to Exercise 2.65 #1002

Closed bpetermann closed 2 months ago

bpetermann commented 4 months ago

In the solution to Exercise 2.65 "intersection_set_as_tree" from chapter 2.3.3, the function declarations for entry, left_branch, right_branch, and make_tree are missing. This omission leads to the following error:

Line 34: Name make_tree not declared.

The same function declarations are in the solution to "union_set_as_tree"

Suggested Fix:

// SICP JS 2.3.3

function intersection_set(set1, set2) {
    if (is_null(set1) || is_null(set2)) {
        return null;
    } else {
        const x1 = head(set1);
        const x2 = head(set2);
        return x1 === x2
               ? pair(x1, intersection_set(tail(set1), tail(set2)))
               : x1 < x2 
               ? intersection_set(tail(set1), set2)
               : // $\texttt{x2 < x1}$
             intersection_set(set1, tail(set2));
    }
}

// Missing declarations
function entry(tree) { return head(tree); }

function left_branch(tree) { return head(tail(tree)); }

function right_branch(tree) { return head(tail(tail(tree))); }

function make_tree(entry, left, right) { 
    return list(entry, left, right);
}
// 

function list_to_tree(elements) {
    return head(partial_tree(elements, length(elements)));
}
...
martin-henz commented 3 months ago

snippets need to have a NAME, for the REQUIRE mechanism to work properly.