Skip to content

Commit aef4e9c

Browse files
authored
fixes #821 (#1016)
1 parent f352aa9 commit aef4e9c

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

xml/chapter2/section5/subsection1.xml

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,54 @@ function contents(datum) {
932932
arithmetic package. This operation should work for ordinary numbers,
933933
rational numbers, and complex numbers.
934934
<LABEL NAME="ex:equ?"/>
935-
</EXERCISE>
935+
<SOLUTION>
936+
<SNIPPET EVAL="no">
937+
<JAVASCRIPT>
938+
// provided by GitHub user clean99
939+
940+
function is_equal(x, y) {
941+
return apply_generic("is_equal", list(x, y));
942+
}
943+
944+
function install_javascript_number_package() {
945+
// ...
946+
947+
put("is_equal", list("javascript_number", "javascript_number"),
948+
(x, y) => x === y);
949+
950+
// ...
951+
}
952+
953+
function install_rational_package() {
954+
// ...
955+
956+
function is_equal(x, y) {
957+
return numer(x) * denom(y) === numer(y) * denom(x);
958+
}
959+
960+
put("is_equal", list("rational", "rational"), is_equal);
961+
962+
// ...
963+
}
964+
965+
function install_complex_package() {
966+
// ...
967+
968+
function is_equal(z1, z2) {
969+
return real_part(z1) === real_part(z2)
970+
? imag_part(z1) === imag_part(z2)
971+
: false;
972+
}
973+
974+
put("is_equal", list("complex", "complex"),
975+
is_equal);
976+
977+
//...
978+
}
979+
</JAVASCRIPT>
980+
</SNIPPET>
981+
</SOLUTION>
982+
</EXERCISE>
936983

937984
<EXERCISE>
938985
Define a generic predicate

0 commit comments

Comments
 (0)