Skip to content

Commit ce4115d

Browse files
authored
bringing all functions that deal with 'dispatch' closer to the original (source-academy#286)
1 parent df4bc2b commit ce4115d

File tree

7 files changed

+50
-39
lines changed

7 files changed

+50
-39
lines changed

xml/chapter2/section1/subsection3.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,14 @@
292292
</SCHEME>
293293
<JAVASCRIPT>
294294
function pair(x, y) {
295-
return m =>
296-
m === 0
297-
? x
298-
: m === 1
299-
? y
300-
: error(m, "Argument not 0 or 1 in pair");
295+
function dispatch(m) {
296+
return m === 0
297+
? x
298+
: m === 1
299+
? y
300+
: error(m, "Argument not 0 or 1 in pair:");
301+
}
302+
return dispatch;
301303
}
302304
function head(z) {
303305
return z(0);

xml/chapter2/section4/subsection3.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ function make_from_real_imag(x, y) {
15261526
: op === "angle"
15271527
? math_atan(y, x)
15281528
: error(op,
1529-
"Unknown op in make_from_real_imag");
1529+
"Unknown op in make_from_real_imag:");
15301530
}
15311531
return dispatch;
15321532
}

xml/chapter3/section1/subsection1.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -892,13 +892,11 @@ function make_account(balance) {
892892
return balance;
893893
}
894894
function dispatch(m) {
895-
if (m === "withdraw") {
896-
return withdraw;
897-
} else if (m === "deposit") {
898-
return deposit;
899-
} else {
900-
return "Unknown request in make_account";
901-
}
895+
return m === "withdraw"
896+
? withdraw
897+
: m === "deposit"
898+
? deposit
899+
: error(m, "Unknown request in make_account");
902900
}
903901
return dispatch;
904902
}

xml/chapter3/section3/subsection1.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,12 +1551,14 @@ function count_pairs(x) {
15511551
</SCHEME>
15521552
<JAVASCRIPT>
15531553
function pair(x, y) {
1554-
return m =>
1555-
m === "head"
1556-
? x
1557-
: m === "tail"
1558-
? y
1559-
: error(m, "Argument not 0 or 1 in pair");
1554+
function dispatch(m) {
1555+
return m === "head"
1556+
? x
1557+
: m === "tail"
1558+
? y
1559+
: error(m, "Undefined operation in pair:");
1560+
}
1561+
return dispatch;
15601562
}
15611563
function head(z) {
15621564
return z("head");

xml/chapter3/section3/subsection2.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,10 +697,10 @@ delete_queue(q1);
697697
</SCHEME>
698698
<JAVASCRIPT>
699699
function make_queue() {
700-
function front_ptr(...) ...
701-
function rear_ptr(...) ...
700+
function front_ptr(...) {...}
701+
function rear_ptr(...) {...}
702702
//definitions of internal functions
703-
function dispatch(m) ...
703+
function dispatch(m) {...}
704704
return dispatch;
705705
}
706706
</JAVASCRIPT>

xml/chapter3/section3/subsection3.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ function make_table() {
525525
? lookup
526526
: m === "insert"
527527
? insert
528-
: "undefined operation -- table";
528+
: error(m, "Unknown operation in table:";
529529
}
530530
return dispatch;
531531
}

xml/chapter3/section4/subsection2.xml

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -480,14 +480,17 @@ function make_account(balance) {
480480
return balance;
481481
}
482482
const protect = make_serializer();
483-
return m => m === "withdraw"
484-
? protect(withdraw)
485-
: m === "deposit"
486-
? protect(deposit)
487-
: m === "balance"
483+
function dispatch(m) {
484+
return m === "withdraw"
485+
? protect(withdraw)
486+
: m === "deposit"
487+
? protect(deposit)
488+
: m === "balance"
488489
? balance
489490
: error(m,
490491
"Unknown request in make_account:");
492+
}
493+
return dispatch;
491494
}
492495
</JAVASCRIPT>
493496
</SNIPPET>
@@ -625,14 +628,17 @@ function make_account(balance) {
625628
return balance;
626629
}
627630
const protect = make_serializer();
628-
return m => m === "withdraw"
629-
? protect(withdraw)
630-
: m === "deposit"
631-
? protect(deposit)
632-
: m === "balance"
631+
function dispatch(m) {
632+
return m === "withdraw"
633+
? protect(withdraw)
634+
: m === "deposit"
635+
? protect(deposit)
636+
: m === "balance"
633637
? protect(_ => balance)(undefined) // serialized
634638
: error(m,
635639
"Unknown request in make_account:");
640+
}
641+
return dispatch;
636642
}
637643
</JAVASCRIPT>
638644
</SNIPPET>
@@ -718,14 +724,17 @@ function make_account(balance) {
718724
const protect = make_serializer();
719725
const protect_withdraw = protect(withdraw);
720726
const protect_deposit = protect(deposit);
721-
return m => m === "withdraw"
722-
? protect_withdraw
723-
: m === "deposit"
724-
? protect_deposit
725-
: m === "balance"
727+
function dispatch(m) {
728+
return m === "withdraw"
729+
? protect_withdraw
730+
: m === "deposit"
731+
? protect_deposit
732+
: m === "balance"
726733
? balance
727734
: error(m,
728735
"Unknown request in make_account:");
736+
}
737+
return dispatch;
729738
}
730739
</JAVASCRIPT>
731740
</SNIPPET>

0 commit comments

Comments
 (0)