Skip to content

Commit b969e50

Browse files
authored
Merge branch 'master' into ex-2-87
2 parents a47899f + 4d8a92f commit b969e50

26 files changed

+1145
-667
lines changed

javascript/latexContent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ export const ending = `
887887
%\\shipoutAnswer
888888
889889
\\newpage
890-
\\markboth{References}{References}
890+
\\renewcommand{\\chaptermark}[1]{\\markboth{References}{References}}
891891
\\input{./others/97references97.tex}
892892
893893
\\newpage

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
},
2626
"homepage": "https://sourceacademy.org/sicpjs",
2727
"devDependencies": {
28-
"@babel/node": "^7.24.6",
29-
"@babel/core": "^7.24.6",
30-
"@babel/preset-env": "^7.24.6",
28+
"@babel/node": "^7.24.7",
29+
"@babel/core": "^7.24.7",
30+
"@babel/preset-env": "^7.24.7",
3131
"fs-extra": "^11.2.0",
3232
"http-server": "^14.1.1",
3333
"husky": "^8.0.3",

static/img_javascript/ex-3-13-sol.png

18 KB
Loading
13.8 KB
Loading
18 KB
Loading
85.9 KB
Loading
57.7 KB
Loading

xml/chapter1/section1/subsection6.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ abs(-5);
231231
<META>alternative-expression</META> and returns its value as the value of the
232232
conditional.<FOOTNOTE>
233233
<INDEX>conditional expression<SUBINDEX>non-boolean value as predicate</SUBINDEX></INDEX>
234-
Conditionals in full JavaScript accept any value, not just a boolean, as the result of evaluating
234+
Conditionals
235+
<LABEL NAME="foot:any-value-as-predicate"/>
236+
in full JavaScript accept any value, not just a boolean, as the result of evaluating
235237
the <META>predicate</META> expression (see footnote<SPACE/><REF NAME="foot:truthy"/>
236238
in section<SPACE/><REF NAME="sec:eval-data-structures"/> for details). The programs in this book
237239
use only boolean values as predicates of conditionals.
@@ -591,8 +593,10 @@ $\vdots$
591593
<INDEX>evaluation<SUBINDEX>of <JAVASCRIPTINLINE>&amp;&amp;</JAVASCRIPTINLINE><ORDER>of ;1</ORDER></SUBINDEX><FRAGILE/></INDEX>
592594
<EM>logical conjunction</EM>, meaning roughly
593595
the same as the English word <QUOTE>and.</QUOTE>
594-
This syntactic form is syntactic sugar<FOOTNOTE>
595-
Syntactic forms that are simply convenient
596+
We assume<FOOTNOTE>This assumption is justified by the restriction mentioned
597+
in footnote<SPACE/><REF NAME="foot:any-value-as-predicate"/>. Full JavaScript
598+
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
599+
sugar<FOOTNOTE>Syntactic forms that are simply convenient
596600
alternative surface structures for things that can be written in more
597601
uniform ways are sometimes called <EM>syntactic sugar</EM>, to use a
598602
phrase coined by
@@ -617,7 +621,7 @@ $\vdots$
617621
<INDEX>evaluation<SUBINDEX>of {\tt "|"|}<ORDER>of ;2</ORDER></SUBINDEX><FRAGILE/></INDEX>
618622
<EM>logical disjunction</EM>, meaning roughly
619623
the same as the English word <QUOTE>or.</QUOTE>
620-
This syntactic form is syntactic sugar for<BR/>
624+
We assume this syntactic form to be syntactic sugar for<BR/>
621625
<META>expression</META><LATEXINLINE>$_1$</LATEXINLINE> <JAVASCRIPTINLINE>?</JAVASCRIPTINLINE>
622626
<JAVASCRIPTINLINE>true</JAVASCRIPTINLINE> <JAVASCRIPTINLINE>:</JAVASCRIPTINLINE>
623627
<META>expression</META><LATEXINLINE>$_2$</LATEXINLINE>.

xml/chapter1/section1/subsection7.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -708,23 +708,21 @@ function sqrt_iter(guess, x) {
708708
<REQUIRES>sqrt</REQUIRES>
709709
<REQUIRES>improve</REQUIRES>
710710
<REQUIRES>sqrt_iter</REQUIRES>
711+
<REQUIRES>square_definition</REQUIRES>
711712
<EXAMPLE>example_1.8</EXAMPLE>
712713
<JAVASCRIPT>
713-
const error_threshold = 0.01;
714+
const relative_tolerance = 0.0001;
714715
function is_good_enough(guess, x) {
715-
return relative_error(guess, improve(guess, x))
716-
&lt; error_threshold;
717-
}
718-
function relative_error(estimate, reference) {
719-
return abs(estimate - reference) / reference;
716+
return abs(square(guess) - x) &lt; guess * relative_tolerance;
720717
}
721718
</JAVASCRIPT>
722719
</SNIPPET>
723720
</SOLUTION>
724721
<SNIPPET HIDE="yes">
725722
<NAME>example_1.8</NAME>
726723
<JAVASCRIPT>
727-
sqrt(3);
724+
display(sqrt(0.0001));
725+
display(sqrt(4000000000000));
728726
</JAVASCRIPT>
729727
<SCHEME>
730728
</SCHEME>

xml/chapter1/section2/subsection6.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -657,12 +657,13 @@ function timed_prime_test(n) {
657657
function start_prime_test(n, start_time) {
658658
return is_prime(n)
659659
? report_prime(get_time() - start_time)
660-
: true;
660+
: false;
661661
}
662662
<SHORT_SPACE_AND_ALLOW_BREAK/>
663663
function report_prime(elapsed_time) {
664664
display(" *** ");
665665
display(elapsed_time);
666+
return true;
666667
}
667668
</JAVASCRIPT>
668669
</SNIPPET>
@@ -726,8 +727,8 @@ function search_for_primes(start, times) {
726727
? true
727728
: start &gt; 2 &amp;&amp; start % 2 === 0
728729
? search_for_primes(start + 1, times)
729-
// if we get undefined -&gt; its a prime
730-
: is_undefined(timed_prime_test(start))
730+
// if we get true, it's a prime
731+
: timed_prime_test(start)
731732
? search_for_primes(start + 2, times - 1)
732733
: search_for_primes(start + 2, times);
733734
}
@@ -740,8 +741,8 @@ function search_for_primes(start, times) {
740741
<REQUIRES>search_for_primes_definition</REQUIRES>
741742
<JAVASCRIPT>
742743
search_for_primes(10000, 3);
743-
// search_for_primes(100000, 3);
744-
// search_for_primes(1000000, 3);
744+
// search_for_primes(10000000, 3);
745+
// search_for_primes(10000000000, 3);
745746
</JAVASCRIPT>
746747
<SCHEME>
747748
</SCHEME>

0 commit comments

Comments
 (0)