Skip to content

fixes #821 #1016

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

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion xml/chapter2/section5/subsection1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,54 @@ function contents(datum) {
arithmetic package. This operation should work for ordinary numbers,
rational numbers, and complex numbers.
<LABEL NAME="ex:equ?"/>
</EXERCISE>
<SOLUTION>
<SNIPPET EVAL="no">
<JAVASCRIPT>
// provided by GitHub user clean99

function is_equal(x, y) {
return apply_generic("is_equal", list(x, y));
}

function install_javascript_number_package() {
// ...

put("is_equal", list("javascript_number", "javascript_number"),
(x, y) => x === y);

// ...
}

function install_rational_package() {
// ...

function is_equal(x, y) {
return numer(x) * denom(y) === numer(y) * denom(x);
}

put("is_equal", list("rational", "rational"), is_equal);

// ...
}

function install_complex_package() {
// ...

function is_equal(z1, z2) {
return real_part(z1) === real_part(z2)
? imag_part(z1) === imag_part(z2)
: false;
}

put("is_equal", list("complex", "complex"),
is_equal);

//...
}
</JAVASCRIPT>
</SNIPPET>
</SOLUTION>
</EXERCISE>

<EXERCISE>
Define a generic predicate
Expand Down
Loading