Skip to content

Commit 668d276

Browse files
committed
Add crude pdf output via LaTeX
1 parent 45f5ceb commit 668d276

19 files changed

+426
-74
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
.tern-port
2222
/toc.txt
2323
/img/cover.xcf
24+
/img/generated/*
2425
/epub/[012]*.xhtml
2526
/epub/hints.xhtml
2627
/epub/img/*

Diff for: 02_program_structure.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ if (!isNaN(theNumber)) {
444444
{{index ["if keyword", chaining]}}
445445

446446
If we have more than two paths to choose from, multiple `if`/`else`
447-
pairs can be chained together. Here's an example:
447+
pairs can be "chained" together. Here's an example:
448448

449449
```
450450
let num = Number(prompt("Pick a number"));
@@ -614,7 +614,7 @@ amount.
614614
{{index syntax, "while loop", "counter variable"}}
615615

616616
Many loops follow the pattern seen in the `while` examples. First, a
617-
counter binding is created to track the progress of the loop. Then
617+
"counter" binding is created to track the progress of the loop. Then
618618
comes a `while` loop, whose test expression usually checks whether the
619619
counter has reached its end value. At the end of the loop body, the
620620
counter is updated to track progress.
@@ -639,7 +639,7 @@ for (let number = 0; number <= 12; number = number + 2) {
639639
This program is exactly equivalent to the
640640
[earlier](program_structure#loops) even-number-printing example. The
641641
only change is that all the ((statement))s that are related to the
642-
state of the loop are grouped together after `for`.
642+
"state" of the loop are grouped together after `for`.
643643

644644
The ((parentheses)) after a `for` keyword must contain two
645645
((semicolon))s. The part before the first semicolon _initializes_ the
@@ -720,7 +720,7 @@ iteration.
720720

721721
{{index assignment, "+= operator", "-= operator", "/= operator", "*= operator", state, "side effect"}}
722722

723-
Especially when looping, a program often needs to update a binding
723+
Especially when looping, a program often needs to "update" a binding
724724
to hold a value based on that binding's previous value.
725725

726726
```{test: no}
@@ -1010,7 +1010,7 @@ number, so you'll have to create an `if`/`else if`/`else` chain.
10101010
{{index "|| operator", ["if keyword", chaining]}}
10111011

10121012
The second version of the program has a straightforward solution and a
1013-
clever one. The simple way is to add another conditional branch to
1013+
clever one. The simple way is to add another conditional "branch" to
10141014
precisely test the given condition. For the clever method, build up a
10151015
string containing the word or words to output, and print either this
10161016
word or the number if there is no word, potentially by making good use
@@ -1024,7 +1024,7 @@ hint}}
10241024

10251025
Write a program that creates a string that represents an 8×8 grid,
10261026
using newline characters to separate lines. At each position of the
1027-
grid there is either a space or a “#” character. The characters should
1027+
grid there is either a space or a "#" character. The characters should
10281028
form a chess board.
10291029

10301030
Passing this string to `console.log` should show something like this:

Diff for: 03_functions.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -393,18 +393,18 @@ function. In the other case, it jumps to the end of the program.
393393

394394
The place where the computer stores this context is the _((call
395395
stack))_. Every time a function is called, the current context is
396-
stored on top of this stack. When the function returns, it removes
396+
stored on top of this "stack". When the function returns, it removes
397397
the top context from the stack and uses it to continue execution.
398398

399399
{{index "infinite loop", "stack overflow", recursion}}
400400

401401
Storing this stack requires space in the computer's memory. When the
402-
stack grows too big, the computer will fail with a message like out
403-
of stack space or too much recursion. The following code
402+
stack grows too big, the computer will fail with a message like "out
403+
of stack space" or "too much recursion". The following code
404404
illustrates this by asking the computer a really hard question, which
405405
causes an infinite back-and-forth between two functions. Rather, it
406406
_would_ be infinite, if the computer had an infinite stack. As it is,
407-
we will run out of space, or blow the stack.
407+
we will run out of space, or "blow the stack".
408408

409409
```{test: no}
410410
function chicken() {
@@ -507,7 +507,7 @@ console.log("C", "O", 2);
507507
{{index "call stack", "local binding", [function, "as value"], scope}}
508508

509509
The ability to treat functions as values, combined with the fact that
510-
local bindings are re-created every time a function is called,
510+
local bindings are "re-created" every time a function is called,
511511
brings up an interesting question. What happens to local bindings when
512512
the function call that created them is no longer active?
513513

@@ -536,7 +536,7 @@ can't trample on one another's local bindings.
536536

537537
This feature—being able to reference a specific instance of local
538538
bindings in an enclosing function—is called _((closure))_. A function
539-
that closes over some local bindings is called _a_ closure. This
539+
that "closes over" some local bindings is called _a_ closure. This
540540
behavior not only frees you from having to worry about lifetimes of
541541
bindings but also allows for some creative use of function values.
542542

@@ -645,7 +645,7 @@ if necessary.
645645
Recursion is not always just a inefficient alternative to looping.
646646
Some problems are really easier to solve with recursion than with
647647
loops. Most often these are problems that require exploring or
648-
processing several branches, each of which might branch out again
648+
processing several "branches", each of which might branch out again
649649
into more branches.
650650

651651
{{id recursive_puzzle}}
@@ -883,7 +883,7 @@ and so on.
883883

884884
A useful principle is not to add cleverness unless you are absolutely
885885
sure you're going to need it. It can be tempting to write general
886-
((framework))s for every bit of functionality you come across.
886+
"((framework))s" for every bit of functionality you come across.
887887
Resist that urge. You won't get any real work done, you'll just end up
888888
writing a lot of code that you'll never use.
889889

@@ -1072,12 +1072,12 @@ In other words, a two-character string has length 2, and its
10721072
characters have positions 0 and 1.
10731073

10741074
Write a function `countBs` that takes a string as its only argument
1075-
and returns a number that indicates how many uppercase “B” characters
1075+
and returns a number that indicates how many uppercase "B" characters
10761076
there are in the string.
10771077

10781078
Next, write a function called `countChar` that behaves like `countBs`,
10791079
except it takes a second argument that indicates the character that is
1080-
to be counted (rather than counting only uppercase “B” characters).
1080+
to be counted (rather than counting only uppercase "B" characters).
10811081
Rewrite `countBs` to make use of this new function.
10821082

10831083
{{if interactive

Diff for: 04_data.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
{{quote {author: "Charles Babbage", title: "Passages from the Life of a Philosopher (1864)", chapter: true}
66

7-
On two occasions I have been asked, Pray, Mr. Babbage, if you put
8-
into the machine wrong figures, will the right answers come out?
7+
On two occasions I have been asked, 'Pray, Mr. Babbage, if you put
8+
into the machine wrong figures, will the right answers come out?'
99
[...] I am not able rightly to apprehend the kind of confusion of
1010
ideas that could provoke such a question.
1111

@@ -156,15 +156,15 @@ difference is in how `x` is interpreted. When using a dot, the word
156156
after the dot is the literal name of the property. When using square
157157
brackets, the expression between the brackets is _evaluated_ to get
158158
the property name. Whereas `value.x` fetches the property of `value`
159-
named “x”, `value[x]` tries to evaluate the expression `x` and uses
159+
named "x", `value[x]` tries to evaluate the expression `x` and uses
160160
the result as the property name.
161161

162162
So if you know that the property you are interested in is called
163-
length, you say `value.length`. If you want to extract the property
163+
"length", you say `value.length`. If you want to extract the property
164164
named by the value held in the binding `i`, you say `value[i]`.
165165
Property names can be any string, and the dot notation only allows
166166
names that look like valid binding names, so if you want to access a
167-
property named “2” or John Doe, you must use square brackets:
167+
property named "2" or "John Doe", you must use square brackets:
168168
`value[2]` or `value["John Doe"]`.
169169

170170
The elements in an ((array)) are stored as the array's properties, using
@@ -209,8 +209,8 @@ value whose property we called. How this works is described in
209209
[Chapter ?](object#obj_methods).
210210

211211
Properties that contain functions are generally called _methods_ of
212-
the value they belong to. As in, _toUpperCase_ is a method of a
213-
string.
212+
the value they belong to. As in, "_toUpperCase_ is a method of a
213+
string".
214214

215215
{{id array_methods}}
216216

@@ -374,7 +374,7 @@ arms in a neat row, labeled with numbers.
374374

375375
{{index journal, "weresquirrel example"}}
376376

377-
So we can represent Jacques journal as an array of objects.
377+
So we can represent Jacques' journal as an array of objects.
378378

379379
```{test: wrap}
380380
let journal = [
@@ -448,7 +448,7 @@ contains the same properties as `object1` but lives a separate life.
448448
JavaScript's `==` operator, when comparing objects, will return `true`
449449
only if both objects are precisely the same value. Comparing different
450450
objects will return `false`, even if they have identical contents.
451-
There is no deep comparison operation built into JavaScript, which
451+
There is no "deep" comparison operation built into JavaScript, which
452452
looks at object's contents, but it is possible to write it yourself
453453
(which will be one of the [exercises](data#exercise_deep_compare) at
454454
the end of this chapter).
@@ -1220,7 +1220,7 @@ like a good approach.
12201220

12211221
What we can do is _serialize_ the data. That means it is converted
12221222
into a flat description. A popular format is called _((JSON))_
1223-
(pronounced Jason), which stands for JavaScript Object Notation. It
1223+
(pronounced "Jason"), which stands for JavaScript Object Notation. It
12241224
is widely used as a data storage and communication format on the Web,
12251225
even in languages other than JavaScript.
12261226

@@ -1305,7 +1305,7 @@ whether it does indeed return 55.
13051305
{{index "optional argument"}}
13061306

13071307
As a bonus assignment, modify your `range` function to take an
1308-
optional third argument that indicates the step value used to build
1308+
optional third argument that indicates the "step" value used to build
13091309
up the array. If no step is given, the array elements go up by
13101310
increments of one, corresponding to the old behavior. The function
13111311
call `range(1, 10, 2)` should return `[1, 3, 5, 7, 9]`. Make sure it
@@ -1518,7 +1518,7 @@ list and the loop is finished.
15181518
{{index recursion}}
15191519

15201520
The recursive version of `nth` will, similarly, look at an ever
1521-
smaller part of the tail of the list and at the same time count down
1521+
smaller part of the "tail" of the list and at the same time count down
15221522
the index until it reaches zero, at which point it can return the
15231523
`value` property of the node it is looking at. To get the zeroeth
15241524
element of a list, you simply take the `value` property of its head

Diff for: 05_higher_order.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ console.log(filter(SCRIPTS, script => script.living));
359359
{{index [function, "as value"], [function, application]}}
360360

361361
This uses the argument named `test`, a function value, to fill in a
362-
gap in the computation. The `test` function is called for each
362+
"gap" in the computation. The `test` function is called for each
363363
element, and its return value determines whether an element is
364364
included in the returned array.
365365

@@ -394,7 +394,7 @@ which is easier to inspect.
394394
The `map` method transforms an array by applying a function to all of
395395
its elements and building a new array from the returned values. The
396396
new array will have the same length as the input array, but its
397-
content will have been mapped to a new form by the function.
397+
content will have been "mapped" to a new form by the function.
398398

399399
```
400400
function map(array, transform) {
@@ -739,7 +739,7 @@ function textScripts(text) {
739739
}).join(", ");
740740
}
741741
742-
console.log(textScripts('英国的狗说woof, 俄罗斯的狗说тяв'));
742+
console.log(textScripts('英国的狗说"woof", 俄罗斯的狗说"тяв"'));
743743
// → 61% Han, 22% Latin, 17% Cyrillic
744744
```
745745

@@ -765,7 +765,7 @@ string it is given in between each of the elements of the array.
765765

766766
Being able to pass function values to other functions is not just a
767767
gimmick—it's a deeply useful aspect of JavaScript. It allows us to
768-
write functions that model computations with gaps in them. The code
768+
write functions that model computations with "gaps" in them. The code
769769
that calls these functions can fill in the gaps by providing function
770770
values.
771771

@@ -784,7 +784,7 @@ the position of the first element that matches a predicate.
784784
{{index "flattening (exercise)", "reduce method", "concat method", array}}
785785

786786
Use the `reduce` method in combination with the `concat` method to
787-
flatten an array of arrays into a single array that has all the
787+
"flatten" an array of arrays into a single array that has all the
788788
elements of the input arrays.
789789

790790
{{if interactive

Diff for: 06_object.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ A property like `speak(line)` in an object expression is a shorthand
246246
for defining methods. It creates a property called `speak` and gives
247247
it a function as its value.
248248

249-
The proto rabbit acts as a container for the properties that are
249+
The "proto" rabbit acts as a container for the properties that are
250250
shared by all rabbits. An individual rabbit object, like the killer
251251
rabbit, contains properties that apply only to itself—in this case its
252252
type—and derives shared properties from its prototype.
@@ -268,6 +268,8 @@ of a class share the same value, such as ((method))s. Properties that
268268
differ per instance, such as our rabbits' `type` ((property)), need to
269269
be stored directly in the objects themselves.
270270

271+
{{id constructors}}
272+
271273
So in order to create an instance of a given class, you have to make
272274
an object that derives from the proper prototype, but you _also_ have
273275
to make sure it, itself, has the properties that instances of this
@@ -441,7 +443,7 @@ Calling `toString` on an array gives a result similar to calling
441443
`.join(",")` on it—it puts commas between the values in the array.
442444
Directly calling `Object.prototype.toString` with an array produces a
443445
different string. That function doesn't know about arrays, so it
444-
simply puts the word object and the name of the type between square
446+
simply puts the word "object" and the name of the type between square
445447
brackets.
446448

447449
```
@@ -1020,7 +1022,7 @@ to properties of the same name.
10201022

10211023
Give the `Vec` prototype two methods, `plus` and `minus`, that take
10221024
another vector as a parameter and return a new vector that has the sum
1023-
or difference of the two vectors (the one in `this` and the
1025+
or difference of the two vectors' (the one in `this` and the
10241026
parameter) _x_ and _y_ values.
10251027

10261028
Add a ((getter)) property `length` to the prototype that computes the

Diff for: 07_robot.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ quote}}
1111

1212
{{index "artificial intelligence", "Dijkstra, Edsger", "project chapter", "reading code", "writing code"}}
1313

14-
In project chapters, I'll stop pummeling you with new theory for a
14+
In "project" chapters, I'll stop pummeling you with new theory for a
1515
brief moment and instead work through a program with you. Theory is
1616
indispensable when learning to program, but it is best accompanied by
1717
reading and understanding nontrivial programs.
@@ -120,7 +120,7 @@ programs are often hard to understand and thus easy to break.
120120

121121
{{quote {author: "Joe Armstrong", title: "interviewed in Coders at Work"}
122122

123-
The problem with object-oriented languages is theyve got all this
123+
The problem with object-oriented languages is they've got all this
124124
implicit environment that they carry around with them. You wanted a
125125
banana but what you got was a gorilla holding the banana and the
126126
entire jungle.

Diff for: 08_error.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ Let's write out its value at the start of the loop.
331331

332332
_Right_. Dividing 13 by 10 does not produce a whole number. Instead of
333333
`n /= base`, what we actually want is `n = Math.floor(n / base)` so
334-
that the number is properly shifted to the right.
334+
that the number is properly "shifted" to the right.
335335

336336
{{index "JavaScript console", "debugger statement"}}
337337

@@ -449,7 +449,7 @@ this stack, throwing away all the call contexts it encounters.
449449
If exceptions always zoomed right down to the bottom of the stack,
450450
they would not be of much use. They'd just provide a novel way to blow
451451
up your program. Their power lies in the fact that you can set
452-
obstacles along the stack to _catch_ the exception as it is zooming
452+
"obstacles" along the stack to _catch_ the exception as it is zooming
453453
down. Once you've caught an exception, you can do something with it to
454454
address the problem, and then continue to run the program.
455455

@@ -575,8 +575,8 @@ there is no problem.
575575
But that isn't always practical. So there is another feature that
576576
`try` statements have. They may be followed by a `finally` block
577577
either instead of or in addition to a `catch` block. A `finally` block
578-
means No matter _what_ happens, run this code after trying to run the
579-
code in the `try` block. If a function has to clean something up, the
578+
means "No matter _what_ happens, run this code after trying to run the
579+
code in the `try` block". If a function has to clean something up, the
580580
cleanup code should usually be put into a `finally` block.
581581

582582
```{includeCode: true}

0 commit comments

Comments
 (0)