Skip to content

Commit 4345b40

Browse files
committed
fixes #823
1 parent 7b7e2a5 commit 4345b40

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

xml/chapter2/section5/subsection1.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,54 @@ function contents(datum) {
947947
arithmetic package. This operation should work for ordinary numbers,
948948
rational numbers, and complex numbers.
949949
<LABEL NAME="ex:=zero?"/>
950+
<SOLUTION>
951+
<SNIPPET EVAL="no">
952+
<JAVASCRIPT>
953+
// provided by GitHub user clean99
954+
955+
function is_equal_to_zero(x) {
956+
return apply_generic("is_equal_to_zero", list(x));
957+
}
958+
959+
function install_javascript_number_package() {
960+
// ...
961+
962+
put("is_equal_to_zero", "javascript_number",
963+
x => x === 0);
964+
965+
// ...
966+
}
967+
968+
function install_rational_package() {
969+
// ...
970+
971+
function is_equal_to_zero(x) {
972+
return numer(x) === 0;
973+
}
974+
975+
put("is_equal_to_zero", "rational",
976+
is_equal_to_zero);
977+
978+
// ...
979+
}
980+
981+
function install_complex_package() {
982+
// ...
983+
984+
function is_equal_to_zero(z) {
985+
return real_part(z) === 0
986+
? imag_part(z) === 0
987+
: false;
988+
}
989+
990+
put("is_equal_to_zero", "complex",
991+
is_equal_to_zero);
992+
993+
//...
994+
}
995+
</JAVASCRIPT>
996+
</SNIPPET>
997+
</SOLUTION>
950998
</EXERCISE>
951999

9521000
<INDEX>generic arithmetic operations<CLOSE/></INDEX>

0 commit comments

Comments
 (0)