File tree Expand file tree Collapse file tree 1 file changed +48
-1
lines changed Expand file tree Collapse file tree 1 file changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -932,7 +932,54 @@ function contents(datum) {
932
932
arithmetic package. This operation should work for ordinary numbers,
933
933
rational numbers, and complex numbers.
934
934
<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 >
936
983
937
984
<EXERCISE >
938
985
Define a generic predicate
You can’t perform that action at this time.
0 commit comments