Skip to content

Commit

Permalink
revamps chapter 3 (source-academy#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-henz authored Jun 13, 2020
1 parent e1f8648 commit 1ede7cd
Show file tree
Hide file tree
Showing 35 changed files with 4,179 additions and 2,842 deletions.
12 changes: 1 addition & 11 deletions javascript/parseXmlHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export let chapterIndex = "";
export let toIndexFolder = "../";

const tagsToRemoveDefault = new Set([
"#comment",
"ATTRIBUTION",
"AUTHOR",
"#comment",
"COMMENT",
"WEB_ONLY",
"PDF_ONLY",
Expand All @@ -57,7 +57,6 @@ const tagsToRemoveDefault = new Set([
const ignoreTagsDefault = new Set([
"CHAPTERCONTENT",
"NOBR",
"span",
"SPLIT",
"SPLITINLINE",
"JAVASCRIPT"
Expand All @@ -76,12 +75,8 @@ const preserveTagsDefault = new Set([
"CITATION",
"TT",
"TABLE",
"table",
"TR",
"tr",
"TD",
"td",
"kbd",
"p",
"REFERENCE"
]);
Expand Down Expand Up @@ -166,11 +161,6 @@ const processTextFunctionsDefaultHtml = {
writeTo.push("\n</CHAPTER></div></div>\n");
},

em: (node, writeTo) => {
node.nodeName = "EM";
processTextHtml(node, writeTo);
},

EM_NO_INDEX: (node, writeTo) => {
node.nodeName = "EM";
processTextHtml(node, writeTo);
Expand Down
11 changes: 1 addition & 10 deletions javascript/parseXmlHtml_split.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export let chapterIndex = "";
export let toIndexFolder = "../";

export const tagsToRemove = new Set([
"#comment",
"ATTRIBUTION",
"AUTHOR",
"#comment",
"COMMENT",
"CHANGE",
"EDIT",
Expand All @@ -52,7 +52,6 @@ export const tagsToRemove = new Set([
export const ignoreTags = new Set([
"CHAPTERCONTENT",
"NOBR",
"span",
"SPLIT",
"SPLITINLINE",
"JAVASCRIPT"
Expand All @@ -71,12 +70,8 @@ export const preserveTags = new Set([
"CITATION",
"TT",
"TABLE",
"table",
"TR",
"tr",
"TD",
"td",
"kbd",
"p",
"REFERENCE"
]);
Expand Down Expand Up @@ -122,10 +117,6 @@ export const processTextFunctionsHtml = {
processTextFunctionsHtml["ABOUT"](node, writeTo),
MATTER: (node, writeTo) => processTextFunctionsHtml["ABOUT"](node, writeTo),

br: (node, writeTo) => {
writeTo.push("<br>");
},

BR: (node, writeTo) => processTextFunctionsHtml["br"](node, writeTo),

CHAPTER: (node, writeTo) => {
Expand Down
3 changes: 2 additions & 1 deletion javascript/processingFunctions/processSnippetHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const setupSnippetsHtml = node => {
};

const recursiveGetRequires = (name, seen) => {
// console.log("in recursiveGetRequires: " + name);
if (seen.has(name)) return;
const snippetEntry = snippetStore[name];
if (!snippetEntry) {
Expand Down Expand Up @@ -101,7 +102,7 @@ export const processSnippetHtml = (node, writeTo, split) => {
let nameStr;
if (snippetName) {
nameStr = snippetName.firstChild.nodeValue;
// console.log(nameStr);
// console.log(nameStr);
const reqSet = new Set();
recursiveGetRequires(nameStr, reqSet);
const examples = node.getElementsByTagName("EXAMPLE");
Expand Down
11 changes: 11 additions & 0 deletions javascript/processingFunctions/processSnippetJs.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ const recursiveGetRequires = (name, seen) => {
export const processSnippetJs = (node, writeTo, fileFormat) => {
const jsSnippet = node.getElementsByTagName("JAVASCRIPT")[0];
if (jsSnippet) {
if (node.getAttribute("CHAP") || node.getAttribute("VARIANT")) {
writeTo.push("// ");
if (node.getAttribute("CHAP")) {
writeTo.push("chapter=" + node.getAttribute("CHAP") + " ");
}
if (node.getAttribute("VARIANT")) {
writeTo.push("variant=" + node.getAttribute("VARIANT") + " ");
}
writeTo.push("\n");
}

// JavaScript source for running. Overrides JAVASCRIPT if present.
let jsRunSnippet = node.getElementsByTagName("JAVASCRIPT_RUN")[0];
let jsTestSnippet = node.getElementsByTagName("JAVASCRIPT_TEST")[0];
Expand Down
14 changes: 10 additions & 4 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,23 @@ passed=0
failed=0

# $1 is the source file to be tested
# $2 is the test file
# $3 is the chapter
# $4 is the variant
# $2 is the chapter
# $3 is the variant

test_source() {
# echo $1
# echo $2
# echo $3
if [ $3 ]; then
variant=$3
else
variant=$DEFAULT_VARIANT
fi
# echo "$(cat $1 | tail -1 | cut -c 1-13)"
if [ "$(cat $1 | tail -1 | cut -c 1-13)" = "// expected: " ]
then
echo "${normal}$1, expecting: $(cat $1 | tail -1 | cut -c14-)"
DIFF=$(diff <($JS_SLANG -e --chapter=$2 "$(cat $1)") \
DIFF=$(diff <($JS_SLANG -e --chapter=$2 --variant=$variant "$(cat $1)") \
<(cat $1 | tail -1 | cut -c14-))
if [ "$DIFF" = "" ]
then passed=$(($passed+1)); echo "${green}PASS"
Expand Down
1 change: 0 additions & 1 deletion static/assets/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,6 @@ th {
text-align: inherit;
}


label {
display: inline-block;
margin-bottom: 0.5rem;
Expand Down
2 changes: 1 addition & 1 deletion xml/chapter1/section1/subsection2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
names to refer to computational
<SPLITINLINE>
<SCHEME>objects.</SCHEME>
<JAVASCRIPT>objects, and our first such means are <em>constants</em>.
<JAVASCRIPT>objects, and our first such means are <EM>constants</EM>.
</JAVASCRIPT>
</SPLITINLINE>
<COMMENT>The second such means are variables, which are syntactically
Expand Down
8 changes: 4 additions & 4 deletions xml/chapter1/section1/subsection3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@
tree, as shown in
<SPLITINLINE>
<SCHEME>
Figure <REF NAME="fig:tree-comb"/>.
figure <REF NAME="fig:tree-comb_scheme"/>.
</SCHEME>
<JAVASCRIPT>
Figure <REF NAME="fig:tree-comb-javascript"/>.
figure <REF NAME="fig:tree-comb"/>.
</JAVASCRIPT>
</SPLITINLINE>
Each combination is represented by a
Expand All @@ -146,15 +146,15 @@
<SPLIT>
<SCHEME>
<FIGURE src="img_original/ch1-Z-G-1.svg">
<LABEL NAME="fig:tree-comb"/>
<LABEL NAME="fig:tree-comb_scheme"/>
<CAPTION>Tree representation, showing the value of each subcombination.
</CAPTION>
</FIGURE>
</SCHEME>
<JAVASCRIPT>
<FIGURE>
<FIGURE src="img_javascript/ch1-Z-G-1.svg"></FIGURE>
<LABEL NAME="fig:tree-comb-javascript"/>
<LABEL NAME="fig:tree-comb"/>
<CAPTION>Tree representation, showing the value of each subexpression.
</CAPTION>
</FIGURE>
Expand Down
4 changes: 2 additions & 2 deletions xml/chapter1/section1/subsection8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@
<SPLITINLINE>
<SCHEME>
procedures
(shown in Figure<SPACE/><REF NAME="fig:sqrt-decomposition"/>)
(shown in figure<SPACE/><REF NAME="fig:sqrt-decomposition"/>)
</SCHEME>
<JAVASCRIPT>
functions
(shown in Figure<SPACE/><REF NAME="fig:sqrt-decomposition_new"/>)
(shown in figure<SPACE/><REF NAME="fig:sqrt-decomposition_new"/>)
</JAVASCRIPT>
</SPLITINLINE>
that mirrors the decomposition of the problem into subproblems.
Expand Down
4 changes: 2 additions & 2 deletions xml/chapter2/section1/subsection2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
shown in
<SPLITINLINE>
<SCHEME>
Figure<SPACE/><REF NAME="fig:abstraction-barriers_scheme"/>.
figure<SPACE/><REF NAME="fig:abstraction-barriers_scheme"/>.
</SCHEME>
<JAVASCRIPT>
Figure<SPACE/><REF NAME="fig:abstraction-barriers"/>.
figure<SPACE/><REF NAME="fig:abstraction-barriers"/>.
</JAVASCRIPT>
</SPLITINLINE>
The horizontal lines represent <EM>abstraction barriers</EM> that isolate
Expand Down
14 changes: 7 additions & 7 deletions xml/chapter2/section2/subsection2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ pair(list(1, 2), list(3, 4));
tree, and elements that are themselves sequences are subtrees.
<SPLITINLINE>
<SCHEME>Figure<SPACE/><REF NAME="fig:list-as-tree_scheme"/></SCHEME>
<JAVASCRIPT><REF NAME="fig:list-as-tree"/></JAVASCRIPT>
<JAVASCRIPT>Figure<SPACE/><REF NAME="fig:list-as-tree"/></JAVASCRIPT>
</SPLITINLINE>
shows the structure in
<SPLITINLINE>
<SCHEME>
Figure<SPACE/><REF NAME="fig:cons-of-2-lists_scheme"/>
figure<SPACE/><REF NAME="fig:cons-of-2-lists_scheme"/>
</SCHEME>
<JAVASCRIPT>
Figure<SPACE/><REF NAME="fig:cons-of-2-lists"/>
figure<SPACE/><REF NAME="fig:cons-of-2-lists"/>
</JAVASCRIPT>
</SPLITINLINE>
viewed as a tree.
Expand All @@ -88,7 +88,7 @@ pair(list(1, 2), list(3, 4));
<FIGURE src="img_original/ch2-Z-G-16.svg">
<LABEL NAME="fig:list-as-tree_scheme"/>
<CAPTION>The list structure in
Figure<SPACE/><REF NAME="fig:cons-of-2-lists_scheme"/>
figure<SPACE/><REF NAME="fig:cons-of-2-lists_scheme"/>
viewed as a tree.
</CAPTION>
</FIGURE>
Expand All @@ -97,7 +97,7 @@ pair(list(1, 2), list(3, 4));
<FIGURE src="img_javascript/ch2-Z-G-16.svg">
<LABEL NAME="fig:list-as-tree"/>
<CAPTION>The list structure in
Figure<SPACE/><REF NAME="fig:cons-of-2-lists"/> viewed as a tree.
figure<SPACE/><REF NAME="fig:cons-of-2-lists"/> viewed as a tree.
</CAPTION>
</FIGURE>
</JAVASCRIPT>
Expand Down Expand Up @@ -420,8 +420,8 @@ count_leaves(pair(list(1, 2), list(3, 4)));
Give the result printed by the interpreter, the corresponding
box-and-pointer structure, and the interpretation of this as a tree (as in
<SPLITINLINE>
<SCHEME>Figure<SPACE/><REF NAME="fig:list-as-tree_scheme"/>).</SCHEME>
<JAVASCRIPT>Figure<SPACE/><REF NAME="fig:list-as-tree"/>).</JAVASCRIPT>
<SCHEME>figure<SPACE/><REF NAME="fig:list-as-tree_scheme"/>).</SCHEME>
<JAVASCRIPT>figure<SPACE/><REF NAME="fig:list-as-tree"/>).</JAVASCRIPT>
</SPLITINLINE>
<LABEL NAME="ex:nested-list"/>
<SOLUTION>
Expand Down
6 changes: 3 additions & 3 deletions xml/chapter2/section2/subsection3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ even_fibs(9);
processes in terms of signals flowing through a cascade of stages, each of
which implements part of the program plan, as shown in
<SPLITINLINE>
<SCHEME>Figure<SPACE/><REF NAME="fig:signal-flow-plans_scheme"/>.</SCHEME>
<JAVASCRIPT>Figure<SPACE/><REF NAME="fig:signal-flow-plans"/>.
<SCHEME>figure<SPACE/><REF NAME="fig:signal-flow-plans_scheme"/>.</SCHEME>
<JAVASCRIPT>figure<SPACE/><REF NAME="fig:signal-flow-plans"/>.
</JAVASCRIPT>
</SPLITINLINE>
In
Expand Down Expand Up @@ -2292,7 +2292,7 @@ length(triples_that_sum_to(10, 6));
<QUOTE>eight-queens puzzle</QUOTE> asks how to place eight queens on a
chessboard so that no queen is in check from any other (i.e., no two
queens are in the same row, column, or diagonal). One possible solution
is shown in Figure<SPACE/><REF NAME="fig:8queens"/>. One way to solve the
is shown in figure<SPACE/><REF NAME="fig:8queens"/>. One way to solve the
puzzle is to work across the board, placing a queen in each column.
Once we have placed <LATEXINLINE>$k-1$</LATEXINLINE> queens, we must place
the <LATEXINLINE>$k$</LATEXINLINE>th queen in a position where it does not
Expand Down
8 changes: 4 additions & 4 deletions xml/chapter2/section2/subsection4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ function right_split(painter, n) {
<TEXT>
We can produce balanced patterns by branching upwards as well as towards
the right (see exercise<SPACE/><REF NAME="ex:up-split"/> and
Figure<SPACE/><REF NAME="fig:split-plans"/>).
figure<SPACE/><REF NAME="fig:split-plans"/>).
<SNIPPET EXT="RUNES">
<NAME>corner_split</NAME>
<REQUIRES>right_split</REQUIRES>
Expand Down Expand Up @@ -1532,7 +1532,7 @@ my_painter(my_frame);
can serve as a painter, provided that it takes a frame as argument and
draws something scaled to fit the frame.<FOOTNOTE>
For example, the <SCHEMEINLINE>rogers</SCHEMEINLINE> painter of
Figure<SPACE/><REF NAME="fig:rogers"/> was constructed from a gray-level
figure<SPACE/><REF NAME="fig:rogers"/> was constructed from a gray-level
image. For each point in a given frame, the
<SCHEMEINLINE>rogers</SCHEMEINLINE> painter determines the point in
the image that is mapped to it under the frame coordinate map, and
Expand Down Expand Up @@ -2446,7 +2446,7 @@ function below(painter1, painter2) {
it likely that small changes in a specification will require
correspondingly small changes in the program. For instance, suppose we
wanted to change the image based on <SCHEMEINLINE>wave</SCHEMEINLINE>
shown in Figure<SPACE/><REF NAME="fig:sqlimit-designs"/>. We could work
shown in figure<SPACE/><REF NAME="fig:sqlimit-designs"/>. We could work
at the lowest level to change the detailed appearance of the
<SCHEMEINLINE>wave</SCHEMEINLINE> element; we could work at the middle
level to change the way
Expand All @@ -2468,7 +2468,7 @@ function below(painter1, painter2) {

<EXERCISE>
Make changes to the square limit of <SCHEMEINLINE>wave</SCHEMEINLINE>
shown in Figure<SPACE/><REF NAME="fig:sqlimit-designs"/> by working at
shown in figure<SPACE/><REF NAME="fig:sqlimit-designs"/> by working at
each of the levels described above. In particular:
<OL>
<!--
Expand Down
6 changes: 3 additions & 3 deletions xml/chapter2/section3/subsection3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ function adjoin_set(x,set) {
will tend to be balanced on the average. But this is not a guarantee. For
example, if we start with an empty set and adjoin the numbers 1 through 7
in sequence we end up with the highly unbalanced tree shown in
Figure<SPACE/><REF NAME="fig:unbalanced-tree"/>. In this tree all the left
figure<SPACE/><REF NAME="fig:unbalanced-tree"/>. In this tree all the left
subtrees are empty, so it has no advantage over a simple ordered list. One
way to solve this problem is to define an operation that transforms an
arbitrary tree into a balanced tree with the same elements. Then we can perform this transformation after every few
Expand Down Expand Up @@ -1176,7 +1176,7 @@ function tree_to_list_2(tree) {
<SCHEME>procedures</SCHEME>
<JAVASCRIPT>functions</JAVASCRIPT>
</SPLITINLINE>
produce for the trees in Figure<SPACE/><REF NAME="fig:binary-tree"/>?
produce for the trees in figure<SPACE/><REF NAME="fig:binary-tree"/>?
<!--
%answer: both
<SPLITINLINE><SCHEME>procedures</SCHEME><JAVASCRIPT>functions</JAVASCRIPT></SPLITINLINE>
Expand All @@ -1198,7 +1198,7 @@ function tree_to_list_2(tree) {
<OL>
<LI>
The two procedures produce the same results. For the trees in
Figure<SPACE/><REF NAME="fig:binary-tree"/>, the result will always
figure<SPACE/><REF NAME="fig:binary-tree"/>, the result will always
be <JAVASCRIPTINLINE>list(1, 3, 5, 7, 9, 11)</JAVASCRIPTINLINE>.
</LI>
<LI>
Expand Down
4 changes: 2 additions & 2 deletions xml/chapter2/section3/subsection4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ BACADAEAFABBAAAGAH
decide which branch to follow by testing to see which branch either is
the leaf node for the symbol or contains the symbol in its set.) For
example, starting from the root of the tree in
Figure<SPACE/><REF NAME="fig:huffman"/>, we arrive at the leaf for D by
figure<SPACE/><REF NAME="fig:huffman"/>, we arrive at the leaf for D by
following a right branch, then a left branch, then a right branch, then a
right branch; hence, the code for D is 1011.
</TEXT>
Expand Down Expand Up @@ -167,7 +167,7 @@ BACADAEAFABBAAAGAH
removing them from the set and replacing them with a node that has
these two as its left and right branches. The process stops when
there is only one node left, which is the root of the entire tree.
Here is how the Huffman tree of Figure<SPACE/><REF NAME="fig:huffman"/> was
Here is how the Huffman tree of figure<SPACE/><REF NAME="fig:huffman"/> was
generated:
<SPLIT>
<SCHEME>
Expand Down
2 changes: 1 addition & 1 deletion xml/chapter2/section4/subsection3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ head(tail(head(tail(deriv(list("*", list("*", "x", "y"), list("+", "x", 3)), "x"
<EM>
Choose any additional differentiation rule that you like, such as
the one for exponents
(Exercise<SPACE/><REF NAME="ex:deriv-exponentiation"/>), and
(exercise<SPACE/><REF NAME="ex:deriv-exponentiation"/>), and
install it in this data-directed system.
</EM>
<P/>
Expand Down
2 changes: 1 addition & 1 deletion xml/chapter2/section5/subsection2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ put("exp", list("javascript_number", "javascript_number"),
<EXERCISE>
<INDEX>type(s)<SUBINDEX>raising</SUBINDEX></INDEX>
Suppose you are designing a generic arithmetic system for dealing with
the tower of types shown in Figure<SPACE/><REF NAME="fig:tower"/>:
the tower of types shown in figure<SPACE/><REF NAME="fig:tower"/>:
integer, rational, real, complex. For
each type (except complex), design a
<SPLITINLINE>
Expand Down
Loading

0 comments on commit 1ede7cd

Please sign in to comment.