Skip to content

Commit fce0d13

Browse files
authored
fixes #263 (#271)
* fixes #263 * done, see response in #263 * scripting as discussed; arithmetic example got corrupted; fixed * missed out this one from Tobias' comments
1 parent 104413d commit fce0d13

File tree

7 files changed

+176
-149
lines changed

7 files changed

+176
-149
lines changed

xml/chapter1/chapter1.xml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@
152152
use for this purpose the programming language JavaScript. Just as our
153153
everyday thoughts are usually expressed in our natural language (such
154154
as English, French, or Japanese), and descriptions of quantitative
155-
phenomena are expressed with mathematical notations, our process
156-
descriptions will be expressed in JavaScript.
155+
phenomena are expressed with mathematical notations, our procedural
156+
thoughts will be expressed in JavaScript.
157157
<INDEX>JavaScript<SUBINDEX>history of</SUBINDEX></INDEX>
158158
JavaScript was developed in the early
159159
1990s as a programming language for controlling the behavior
@@ -208,7 +208,7 @@
208208
</SCHEME>
209209
<JAVASCRIPT>
210210
<TEXT>
211-
Despite its inception as a language for controlling browsers, JavaScript
211+
Despite its inception as a language for scripting the Web, JavaScript
212212
<INDEX>interpreter</INDEX>
213213
is a general-purpose programming language. A JavaScript <EM>interpreter</EM>
214214
is a machine that carries out processes described in the JavaScript
@@ -395,11 +395,9 @@
395395
using sophisticated implementation techniques such as Just-In-Time
396396
(JIT) compilation.
397397
The majority of JavaScript programs (as of 2020) are embedded in
398-
web pages and interpreted by browsers, but JavaScript is also used
399-
for scripting dashboard widgets in Apple computers running the OS X
400-
operating system, for controlling software systems such as Adobe
401-
Reader and devices such as universal remote panels, and
402-
in server software, using Node.js.
398+
web pages and interpreted by browsers, but JavaScript is increasingly
399+
used as a general-purpose programming language, using systems such as
400+
Node.js.
403401
</TEXT>
404402
</JAVASCRIPT>
405403
</SPLIT>

xml/chapter1/section1/section1.xml

Lines changed: 126 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,137 @@
1-
<SECTION>
2-
<NAME>The Elements of Programming</NAME>
3-
<LABEL NAME="sec:elements-of-programming"></LABEL>
4-
<INDEX>programming<SUBINDEX>elements of</SUBINDEX></INDEX>
1+
<SECTION>
2+
<NAME>The Elements of Programming</NAME>
3+
<LABEL NAME="sec:elements-of-programming"></LABEL>
4+
<INDEX>programming<SUBINDEX>elements of</SUBINDEX></INDEX>
55

6-
<SECTIONCONTENT/>
6+
<SECTIONCONTENT/>
77

8-
<TEXT>
9-
A powerful programming language is more than just a means for
10-
instructing a computer to perform tasks. The language also serves as
11-
a framework within which we organize our ideas about processes. Thus,
12-
when we describe a language, we should pay particular attention to the
13-
means that the language provides for combining simple ideas to form
14-
more complex ideas. Every powerful language has three mechanisms for
15-
accomplishing this:
16-
<UL>
17-
<LI>
18-
<B>primitive expressions</B>, which represent the simplest
19-
entities the language is concerned with,
20-
<INDEX>primitive expression</INDEX>
21-
</LI>
22-
<LI>
23-
<B>means of combination</B>, by which compound
24-
elements are built from simpler ones, and
25-
<INDEX>means of combination</INDEX>
26-
<INDEX>combination, means of</INDEX>
27-
</LI>
28-
<LI>
29-
<B>means of abstraction</B>, by
30-
which compound elements can be named and manipulated as units.
31-
<INDEX>means of abstraction</INDEX>
32-
</LI>
33-
</UL>
34-
</TEXT>
35-
<TEXT>
36-
In programming, we deal with two kinds of elements:
37-
<INDEX>procedure</INDEX>
38-
<SPLITINLINE><SCHEME>procedures</SCHEME><JAVASCRIPT>functions</JAVASCRIPT></SPLITINLINE>
39-
and
40-
<INDEX>data</INDEX>
41-
data. (Later we will discover that they are really not so distinct.)
42-
Informally, data is <QUOTE>stuff</QUOTE> that we want to manipulate, and
43-
<SPLITINLINE><SCHEME>procedures</SCHEME><JAVASCRIPT>functions</JAVASCRIPT></SPLITINLINE>
44-
are descriptions of the rules for manipulating the data.
45-
Thus, any powerful programming language should be able to describe
46-
primitive data and primitive
47-
<SPLITINLINE><SCHEME>procedures</SCHEME><JAVASCRIPT>functions</JAVASCRIPT></SPLITINLINE>
48-
and should have methods for
49-
combining and abstracting
50-
<SPLITINLINE><SCHEME>procedures</SCHEME><JAVASCRIPT>functions</JAVASCRIPT></SPLITINLINE>
51-
and data.
52-
<INDEX>programming<SUBINDEX>elements of</SUBINDEX></INDEX>
53-
</TEXT>
8+
<TEXT>
9+
A powerful programming language is more than just a means for
10+
instructing a computer to perform tasks. The language also serves as
11+
a framework within which we organize our ideas about processes. Thus,
12+
when we describe a language, we should pay particular attention to the
13+
means that the language provides for combining simple ideas to form
14+
more complex ideas. Every powerful language has three mechanisms for
15+
accomplishing this:
16+
<UL>
17+
<LI>
18+
<B>primitive expressions</B>, which represent the simplest
19+
entities the language is concerned with,
20+
<INDEX>primitive expression</INDEX>
21+
</LI>
22+
<LI>
23+
<B>means of combination</B>, by which compound
24+
elements are built from simpler ones, and
25+
<INDEX>means of combination</INDEX>
26+
<INDEX>combination, means of</INDEX>
27+
</LI>
28+
<LI>
29+
<B>means of abstraction</B>, by
30+
which compound elements can be named and manipulated as units.
31+
<INDEX>means of abstraction</INDEX>
32+
</LI>
33+
</UL>
34+
</TEXT>
35+
36+
<TEXT>
37+
In programming, we deal with two kinds of elements:
38+
<INDEX>procedure</INDEX>
39+
<SPLITINLINE>
40+
<SCHEME>procedures</SCHEME>
41+
<JAVASCRIPT>functions</JAVASCRIPT>
42+
</SPLITINLINE>
43+
and
44+
<INDEX>data</INDEX>
45+
data. (Later we will discover that they are really not so distinct.)
46+
Informally, data is <QUOTE>stuff</QUOTE> that we want to manipulate, and
47+
<SPLITINLINE>
48+
<SCHEME>procedures</SCHEME>
49+
<JAVASCRIPT>functions</JAVASCRIPT>
50+
</SPLITINLINE>
51+
are descriptions of the rules for manipulating the data.
52+
Thus, any powerful programming language should be able to describe
53+
primitive data and primitive
54+
<SPLITINLINE>
55+
<SCHEME>procedures</SCHEME>
56+
<JAVASCRIPT>functions</JAVASCRIPT>
57+
</SPLITINLINE>
58+
and should have methods for
59+
combining and abstracting
60+
<SPLITINLINE>
61+
<SCHEME>procedures</SCHEME>
62+
<JAVASCRIPT>functions</JAVASCRIPT>
63+
</SPLITINLINE>
64+
and data.
65+
<INDEX>programming<SUBINDEX>elements of</SUBINDEX></INDEX>
66+
</TEXT>
5467

55-
<TEXT>
56-
In this chapter we will deal only with simple
57-
<INDEX>numerical data</INDEX><INDEX>data<SUBINDEX>numerical</SUBINDEX></INDEX>
58-
numerical data so that
59-
we can focus on the rules for building
60-
<SPLITINLINE><SCHEME>procedures</SCHEME><JAVASCRIPT>functions</JAVASCRIPT></SPLITINLINE>.<FOOTNOTE>The
61-
characterization of numbers as <QUOTE>simple data</QUOTE>
62-
is a barefaced bluff.
63-
In fact, the treatment of numbers is one of the trickiest and most
64-
confusing aspects of any programming language. Some typical issues
65-
involved are these:
66-
<INDEX>integer(s)</INDEX>
67-
<INDEX>real number</INDEX>
68-
<INDEX>number(s)</INDEX>
69-
<INDEX>integer vs.<SPACE/>real number</INDEX>
70-
<SPLIT><SCHEME>
71-
Some computer systems distinguish <EM>integers</EM>, such as 2, from
72-
<EM>real numbers</EM>, such as 2.71. Is the real number 2.00 different
73-
from the integer 2?
74-
Are the arithmetic operations used
75-
for integers the same as the operations used for real numbers? Does 6
76-
divided by 2 produce 3, or 3.0?
77-
</SCHEME>
78-
</SPLIT>
79-
How large a number can we represent?
80-
How many decimal places of accuracy can we represent?
81-
<SPLIT><SCHEME>
82-
Is the range of
83-
integers the same as the range of real numbers?
84-
</SCHEME></SPLIT>
85-
<INDEX>numerical analysis</INDEX>
86-
<INDEX>roundoff error</INDEX>
87-
<INDEX>truncation error</INDEX>
88-
Above and beyond
89-
these questions, of course, lies a collection of issues concerning
90-
roundoff and truncation errors<EMDASH/>the entire science of numerical
91-
analysis. Since our focus in this book is on large-scale program
92-
design rather than on numerical techniques, we are going to ignore
93-
these problems. The numerical examples in this chapter will exhibit
94-
the usual roundoff behavior that one observes when using arithmetic
95-
operations that preserve a limited number of decimal places of
96-
accuracy in noninteger operations.
97-
<LABEL NAME="foot:number-representation"></LABEL>
98-
</FOOTNOTE>
99-
In later chapters we will see that
100-
these same rules allow us to build
101-
<SPLITINLINE><SCHEME>procedures</SCHEME><JAVASCRIPT>functions</JAVASCRIPT></SPLITINLINE>
102-
to manipulate compound data as well.
103-
</TEXT>
68+
<TEXT>
69+
In this chapter we will deal only with simple
70+
<INDEX>numerical data</INDEX>
71+
<INDEX>data<SUBINDEX>numerical</SUBINDEX></INDEX>
72+
numerical data so that
73+
we can focus on the rules for building
74+
<SPLITINLINE><SCHEME>procedures</SCHEME><JAVASCRIPT>functions</JAVASCRIPT></SPLITINLINE>.<FOOTNOTE>The
75+
<LABEL NAME="foot:number-representation"></LABEL>
76+
characterization of numbers as <QUOTE>simple data</QUOTE> is a barefaced
77+
bluff. In fact, the treatment of numbers is one of the trickiest and most
78+
confusing aspects of any programming language. Some typical issues
79+
involved are these:
80+
<INDEX>integer(s)</INDEX>
81+
<INDEX>real number</INDEX>
82+
<INDEX>number(s)</INDEX>
83+
<INDEX>integer vs.<SPACE/>real number</INDEX>
84+
Some computer systems distinguish <EM>integers</EM>, such as 2,
85+
from <EM>real numbers</EM>, such as 2.71. Is the real number
86+
2.00 different from the integer 2? Are the arithmetic operations
87+
used for integers the same as the operations used for real numbers?
88+
Does 6 divided by 2 produce 3, or 3.0? How large a number can we
89+
represent? How many decimal places of accuracy can we represent?
90+
Is the range of integers the same as the range of real numbers?
91+
<INDEX>numerical analysis</INDEX>
92+
<INDEX>roundoff error</INDEX>
93+
<INDEX>truncation error</INDEX>
94+
Above and beyond these questions, of course, lies a collection of
95+
issues concerning roundoff and truncation errors<EMDASH/>the
96+
entire science of numerical analysis. Since our focus in this
97+
book is on large-scale program design rather than on numerical
98+
techniques, we are going to ignore these problems. The numerical
99+
examples in this chapter will exhibit the usual roundoff behavior
100+
that one observes when using arithmetic operations that preserve
101+
a limited number of decimal places of accuracy in noninteger
102+
operations.
103+
</FOOTNOTE>
104+
In later chapters we will see that
105+
these same rules allow us to build
106+
<SPLITINLINE>
107+
<SCHEME>procedures</SCHEME>
108+
<JAVASCRIPT>functions</JAVASCRIPT>
109+
</SPLITINLINE>
110+
to manipulate compound data as well.
111+
</TEXT>
104112

105-
<!-- Subsection 1 : Expressions -->
106-
&subsection1.1.1;
113+
<!-- Subsection 1 : Expressions -->
114+
&subsection1.1.1;
107115

108-
<!-- Subsection 2 : Naming and the Environment -->
109-
&subsection1.1.2;
116+
<!-- Subsection 2 : Naming and the Environment -->
117+
&subsection1.1.2;
110118

111-
<!-- Subsection 3 : Evaluating Combinations -->
112-
&subsection1.1.3;
119+
<!-- Subsection 3 : Evaluating Combinations -->
120+
&subsection1.1.3;
113121

114-
<!-- Subsection 4 : Compound Procedures -->
115-
&subsection1.1.4;
122+
<!-- Subsection 4 : Compound Procedures -->
123+
&subsection1.1.4;
116124

117-
<!-- Subsection 5 : The Substitution Model for Procedure Application -->
118-
&subsection1.1.5;
125+
<!-- Subsection 5 : The Substitution Model for Procedure Application -->
126+
&subsection1.1.5;
119127

120-
<!-- Subsection 6 : Conditional Expressions and Predicates -->
121-
&subsection1.1.6;
128+
<!-- Subsection 6 : Conditional Expressions and Predicates -->
129+
&subsection1.1.6;
122130

123-
<!-- Subsection 7 : Example: Square Roots by Newtons Method -->
124-
&subsection1.1.7;
131+
<!-- Subsection 7 : Example: Square Roots by Newtons Method -->
132+
&subsection1.1.7;
125133

126-
<!-- Subsection 8 : Procedures as Black-Box Abstractions -->
127-
&subsection1.1.8;
128-
129-
</SECTION>
134+
<!-- Subsection 8 : Procedures as Black-Box Abstractions -->
135+
&subsection1.1.8;
136+
137+
</SECTION>

xml/chapter1/section1/subsection1.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@
435435
<SNIPPET>
436436
<EXPECTED>57</EXPECTED>
437437
<JAVASCRIPT>
438-
3 * (2 * 4 + (3 + 5) + ((10 - 7) + 6
438+
3 * 2 * (4 + (3 - 5)) + 10 * (27 / 6);
439439
</JAVASCRIPT>
440440
</SNIPPET>
441441
which the interpreter would readily evaluate to be 57. We can help

xml/chapter1/section1/subsection2.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,14 @@ size;
107107
<JAVASCRIPT>
108108
<TEXT>
109109
<WEB_ONLY>
110-
Of course, the JavaScript interpreter needs to execute the constant
110+
The JavaScript interpreter needs to execute the constant
111111
declaration for <JAVASCRIPTINLINE>size</JAVASCRIPTINLINE>
112112
before the name <JAVASCRIPTINLINE>size</JAVASCRIPTINLINE> can be used
113113
in an expression. In this online book, the statements that need to be
114-
evaluated before a new statement are omitted for brevity.
115-
However, in order to see and play with the
116-
program, you can click on it.
117-
The program, preceeded by all required statements, then
118-
appears in a new browser tab.
119-
Thus, as a result of clicking on
114+
evaluated before a new statement are omitted for brevity. However, in
115+
order to see and play with the program, you can click on it. The
116+
program, preceeded by all required statements, then appears in a new
117+
browser tab. Thus, as a result of clicking on
120118
<SNIPPET>
121119
<REQUIRES>var_size</REQUIRES>
122120
<JAVASCRIPT>

xml/chapter1/section1/subsection4.xml

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
<QUOTE>To square something, take it times itself.</QUOTE>
6363
</JAVASCRIPT>
6464
</SPLITINLINE>
65+
<COMMENT>
66+
The Scheme and JavaScript phrases differ a bit here, in order to better
67+
match infix notation in JavaScript.
68+
</COMMENT>
6569
This is expressed in our language as
6670
<INDEX>
6771
<JAVASCRIPTINLINE>square</JAVASCRIPTINLINE>
@@ -103,24 +107,32 @@ function square( x ) { return x * x; }
103107
</JAVASCRIPT>
104108
</SNIPPET>
105109
</WEB_ONLY>
106-
<PDF_ONLY>
107-
<SNIPPET EVAL="no">
108-
<JAVASCRIPT>
110+
<SPLIT>
111+
<JAVASCRIPT>
112+
<PDF_ONLY>
113+
<SNIPPET EVAL="no">
114+
<JAVASCRIPT>
109115
function square( x ) { return x * x; }
110-
</JAVASCRIPT>
111-
</SNIPPET>
112-
<LATEX>
113-
\vspace{-4mm}
114-
\hspace{6mm} $\Big\uparrow$ \hspace{13mm} $\Big\uparrow$ \hspace{14mm} $\Big\uparrow$ \hspace{18mm} $\Big\uparrow$ \hspace{6mm} $\Big\uparrow$ \hspace{6mm} $\Big\uparrow$ \hspace{9mm} $\Big\uparrow$
116+
</JAVASCRIPT>
117+
</SNIPPET>
118+
<LATEX>
119+
\vspace{-4mm}
120+
\hspace{6mm} $\Big\uparrow$ \hspace{13mm} $\Big\uparrow$ \hspace{14mm} $\Big\uparrow$ \hspace{18mm} $\Big\uparrow$ \hspace{6mm} $\Big\uparrow$ \hspace{6mm} $\Big\uparrow$ \hspace{9mm} $\Big\uparrow$
115121

116-
\vspace{-2mm}
117-
</LATEX>
118-
<SNIPPET EVAL="no" LATEX="yes">
119-
<JAVASCRIPT>
122+
\vspace{-2mm}
123+
</LATEX>
124+
<SNIPPET EVAL="no" LATEX="yes">
125+
<JAVASCRIPT>
120126
$\;\;\;\;$ To square something, take it times itself.
121-
</JAVASCRIPT>
122-
</SNIPPET>
123-
</PDF_ONLY>
127+
</JAVASCRIPT>
128+
</SNIPPET>
129+
</PDF_ONLY>
130+
<COMMENT>
131+
In the comparison edition, ignore the spacing instructions; they are
132+
making sure the arrows appear in the right places in the PDF version.
133+
</COMMENT>
134+
</JAVASCRIPT>
135+
</SPLIT>
124136
<INDEX>compound procedure</INDEX>
125137
<INDEX>procedure<SUBINDEX>compound</SUBINDEX></INDEX>
126138
We have here a

xml/chapter1/section1/subsection5.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@
124124
<JAVASCRIPT>
125125
f(5)
126126
</JAVASCRIPT>
127+
<JAVASCRIPT_RUN>
128+
f(5);
129+
</JAVASCRIPT_RUN>
127130
</SNIPPET>
128131
where <SCHEMEINLINE>f</SCHEMEINLINE> is the
129132
<SPLITINLINE>

0 commit comments

Comments
 (0)