Skip to content

Commit

Permalink
Merge branch 'master' into 3-3-3-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
RichDom2185 authored Jul 10, 2024
2 parents a3a5c09 + b1a7413 commit 77f487e
Show file tree
Hide file tree
Showing 24 changed files with 1,097 additions and 661 deletions.
2 changes: 1 addition & 1 deletion javascript/latexContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ export const ending = `
%\\shipoutAnswer
\\newpage
\\markboth{References}{References}
\\renewcommand{\\chaptermark}[1]{\\markboth{References}{References}}
\\input{./others/97references97.tex}
\\newpage
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
},
"homepage": "https://sourceacademy.org/sicpjs",
"devDependencies": {
"@babel/node": "^7.24.6",
"@babel/core": "^7.24.6",
"@babel/preset-env": "^7.24.6",
"@babel/node": "^7.24.7",
"@babel/core": "^7.24.7",
"@babel/preset-env": "^7.24.7",
"fs-extra": "^11.2.0",
"http-server": "^14.1.1",
"husky": "^8.0.3",
Expand Down
Binary file added static/img_javascript/ex-3-13-sol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img_javascript/ex-3-14-sol-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img_javascript/ex-3-14-sol-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img_javascript/ex5-1-solution-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img_javascript/ex5-1-solution-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions xml/chapter1/section1/subsection6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ abs(-5);
<META>alternative-expression</META> and returns its value as the value of the
conditional.<FOOTNOTE>
<INDEX>conditional expression<SUBINDEX>non-boolean value as predicate</SUBINDEX></INDEX>
Conditionals in full JavaScript accept any value, not just a boolean, as the result of evaluating
Conditionals
<LABEL NAME="foot:any-value-as-predicate"/>
in full JavaScript accept any value, not just a boolean, as the result of evaluating
the <META>predicate</META> expression (see footnote<SPACE/><REF NAME="foot:truthy"/>
in section<SPACE/><REF NAME="sec:eval-data-structures"/> for details). The programs in this book
use only boolean values as predicates of conditionals.
Expand Down Expand Up @@ -591,8 +593,10 @@ $\vdots$
<INDEX>evaluation<SUBINDEX>of <JAVASCRIPTINLINE>&amp;&amp;</JAVASCRIPTINLINE><ORDER>of ;1</ORDER></SUBINDEX><FRAGILE/></INDEX>
<EM>logical conjunction</EM>, meaning roughly
the same as the English word <QUOTE>and.</QUOTE>
This syntactic form is syntactic sugar<FOOTNOTE>
Syntactic forms that are simply convenient
We assume<FOOTNOTE>This assumption is justified by the restriction mentioned
in footnote<SPACE/><REF NAME="foot:any-value-as-predicate"/>. Full JavaScript
needs to consider the case where the result of evaluating <META>expression</META><LATEXINLINE>$_1$</LATEXINLINE> is neither true nor false.</FOOTNOTE> this syntactic form to be syntactic
sugar<FOOTNOTE>Syntactic forms that are simply convenient
alternative surface structures for things that can be written in more
uniform ways are sometimes called <EM>syntactic sugar</EM>, to use a
phrase coined by
Expand All @@ -617,7 +621,7 @@ $\vdots$
<INDEX>evaluation<SUBINDEX>of {\tt "|"|}<ORDER>of ;2</ORDER></SUBINDEX><FRAGILE/></INDEX>
<EM>logical disjunction</EM>, meaning roughly
the same as the English word <QUOTE>or.</QUOTE>
This syntactic form is syntactic sugar for<BR/>
We assume this syntactic form to be syntactic sugar for<BR/>
<META>expression</META><LATEXINLINE>$_1$</LATEXINLINE> <JAVASCRIPTINLINE>?</JAVASCRIPTINLINE>
<JAVASCRIPTINLINE>true</JAVASCRIPTINLINE> <JAVASCRIPTINLINE>:</JAVASCRIPTINLINE>
<META>expression</META><LATEXINLINE>$_2$</LATEXINLINE>.
Expand Down
12 changes: 5 additions & 7 deletions xml/chapter1/section1/subsection7.xml
Original file line number Diff line number Diff line change
Expand Up @@ -708,23 +708,21 @@ function sqrt_iter(guess, x) {
<REQUIRES>sqrt</REQUIRES>
<REQUIRES>improve</REQUIRES>
<REQUIRES>sqrt_iter</REQUIRES>
<REQUIRES>square_definition</REQUIRES>
<EXAMPLE>example_1.8</EXAMPLE>
<JAVASCRIPT>
const error_threshold = 0.01;
const relative_tolerance = 0.0001;
function is_good_enough(guess, x) {
return relative_error(guess, improve(guess, x))
&lt; error_threshold;
}
function relative_error(estimate, reference) {
return abs(estimate - reference) / reference;
return abs(square(guess) - x) &lt; guess * relative_tolerance;
}
</JAVASCRIPT>
</SNIPPET>
</SOLUTION>
<SNIPPET HIDE="yes">
<NAME>example_1.8</NAME>
<JAVASCRIPT>
sqrt(3);
display(sqrt(0.0001));
display(sqrt(4000000000000));
</JAVASCRIPT>
<SCHEME>
</SCHEME>
Expand Down
2 changes: 1 addition & 1 deletion xml/chapter2/section2/subsection3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ function matrix_times_vector(m, v) {
function transpose(mat) {
return accumulate_n(<METAPHRASE>??</METAPHRASE>, <METAPHRASE>??</METAPHRASE>, mat);
}
function matrix_times_matrix(n, m) {
function matrix_times_matrix(m, n) {
const cols = transpose(n);
return map(<METAPHRASE>??</METAPHRASE>, m);
}
Expand Down
2 changes: 2 additions & 0 deletions xml/chapter2/section3/subsection3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,7 @@ tree_to_list_2(union_set_as_tree(
</JAVASCRIPT>
</SNIPPET>
<SNIPPET>
<NAME>intersection_set_as_tree_solution</NAME>
<REQUIRES>intersection_set_ordered</REQUIRES>
<REQUIRES>list_to_tree</REQUIRES>
<REQUIRES>tree_to_list_2</REQUIRES>
Expand Down Expand Up @@ -1639,6 +1640,7 @@ lookup(3, list(make_record(2, "Venus"),
<LABEL NAME="ex:set-lookup-binary-tree"/>
<SOLUTION>
<SNIPPET>
<NAME>ex_set_lookup_binary_tree</NAME>
<REQUIRES>make_tree_function</REQUIRES>
<REQUIRES>record</REQUIRES>
<EXAMPLE>lookup_example2</EXAMPLE>
Expand Down
4 changes: 2 additions & 2 deletions xml/chapter2/section4/subsection2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function magnitude_rectangular(z) {
square(imag_part_rectangular(z)));
}
function angle_rectangular(z) {
return math_atan(imag_part_rectangular(z),
return math_atan2(imag_part_rectangular(z),
real_part_rectangular(z));
}
function make_from_real_imag_rectangular(x, y) {
Expand Down Expand Up @@ -297,7 +297,7 @@ function angle_polar(z) { return tail(z); }
function make_from_real_imag_polar(x, y) {
return attach_tag("polar",
pair(math_sqrt(square(x) + square(y)),
math_atan(y, x)));
math_atan2(y, x)));
}
<ALLOW_BREAK/>
function make_from_mag_ang_polar(r, a) {
Expand Down
12 changes: 6 additions & 6 deletions xml/chapter2/section4/subsection3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ function install_rectangular_package() {
return math_sqrt(square(real_part(z)) + square(imag_part(z)));
}
function angle(z) {
return math_atan(imag_part(z), real_part(z));
return math_atan2(imag_part(z), real_part(z));
}
function make_from_mag_ang(r, a) {
return pair(r * math_cos(a), r * math_sin(a));
Expand Down Expand Up @@ -508,7 +508,7 @@ function install_polar_package() {
}
function make_from_real_imag(x, y) {
return pair(math_sqrt(square(x) + square(y)),
math_atan(y, x));
math_atan2(y, x));
}

// interface to the rest of the system
Expand Down Expand Up @@ -1551,7 +1551,7 @@ function make_from_real_imag(x, y) {
: op === "magnitude"
? math_sqrt(square(x) + square(y))
: op === "angle"
? math_atan(y, x)
? math_atan2(y, x)
: error(op, "unknown op -- make_from_real_imag");
}
return dispatch;
Expand All @@ -1567,7 +1567,7 @@ function make_from_real_imag(x, y) {
: op === "magnitude"
? math_sqrt(square(x) + square(y))
: op === "angle"
? math_atan(y, x)
? math_atan2(y, x)
: error(op, "unknown op -- make_from_real_imag");
}
return dispatch;
Expand Down Expand Up @@ -1696,7 +1696,7 @@ function install_rectangular_package() {
square(imag_part(z)));
}
function angle(z) {
return math_atan(imag_part(z), real_part(z));
return math_atan2(imag_part(z), real_part(z));
}
function make_from_mag_ang(r, a) {
return pair(r * math_cos(a), r * math_sin(a));
Expand Down Expand Up @@ -1730,7 +1730,7 @@ function install_polar_package() {
}
function make_from_real_imag(x, y) {
return pair(math_sqrt(square(x) + square(y)),
math_atan(y, x));
math_atan2(y, x));
}

// interface to the rest of the system
Expand Down
48 changes: 48 additions & 0 deletions xml/chapter2/section5/subsection1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,54 @@ function install_complex_package() {
arithmetic package. This operation should work for ordinary numbers,
rational numbers, and complex numbers.
<LABEL NAME="ex:=zero?"/>
<SOLUTION>
<SNIPPET EVAL="no">
<JAVASCRIPT>
// provided by GitHub user clean99

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

function install_javascript_number_package() {
// ...

put("is_equal_to_zero", "javascript_number",
x => x === 0);

// ...
}

function install_rational_package() {
// ...

function is_equal_to_zero(x) {
return numer(x) === 0;
}

put("is_equal_to_zero", "rational",
is_equal_to_zero);

// ...
}

function install_complex_package() {
// ...

function is_equal_to_zero(z) {
return real_part(z) === 0
? imag_part(z) === 0
: false;
}

put("is_equal_to_zero", "complex",
is_equal_to_zero);

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

<INDEX>generic arithmetic operations<CLOSE/></INDEX>
Expand Down
4 changes: 2 additions & 2 deletions xml/chapter2/section5/subsection2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ function install_rectangular_package() {
square(imag_part(z)));
}
function angle(z) {
return math_atan(imag_part(z), real_part(z));
return math_atan2(imag_part(z), real_part(z));
}
function make_from_mag_ang(r, a) {
return pair(r * math_cos(a), r * math_sin(a));
Expand Down Expand Up @@ -515,7 +515,7 @@ function install_polar_package() {
}
function make_from_real_imag(x, y) {
return pair(math_sqrt(square(x) + square(y)),
math_atan(y, x));
math_atan2(y, x));
}

// interface to the rest of the system
Expand Down
Loading

0 comments on commit 77f487e

Please sign in to comment.