Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 3.5.1: Exercise 3.50 "optimized" solution function is incorrect #1060

Closed
PossibilityZero opened this issue Oct 4, 2024 · 1 comment

Comments

@PossibilityZero
Copy link
Contributor

The current solution to Exercise 3.50 is given as follows:

function stream_map_2(f, s1, s2) {
    return is_null(s1) || is_null(s2)
        ? null
        : pair(f(head(s1), head(s2)),
                () => stream_map_2(f, stream_tail(s1), stream_tail(s2)));
}

function stream_map_2_optimized(f, s1, s2) {
    return is_null(s1) || is_null(s2)
        ? null
        : pair(f(head(s1), head(s2)),
                memo(() => stream_map_2(f, stream_tail(s1), stream_tail(s2))));
}

The function stream_map_2_optimized as given only uses memoization for the first pair, because it calls stream_map_2. The last line should be changed to

                memo(() => stream_map_2_optimized(f, stream_tail(s1), stream_tail(s2))));
martin-henz added a commit that referenced this issue Oct 4, 2024
@martin-henz
Copy link
Member

OK, fixed in #1062.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants