Skip to content

Missing Function Declarations in Solution to Exercise 2.65 #1002

@bpetermann

Description

@bpetermann

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)));
}
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions