Skip to content

Commit

Permalink
fixes #821 (#1016)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-henz authored Jul 3, 2024
1 parent f352aa9 commit aef4e9c
Showing 1 changed file with 48 additions and 1 deletion.
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

0 comments on commit aef4e9c

Please sign in to comment.