Minor cleanup.
This commit is contained in:
parent
b48419ec1a
commit
5b852e7964
|
|
@ -484,7 +484,7 @@
|
|||
"- We're tearing down two lists simultaneously.\n",
|
||||
"- They might not be the same length.\n",
|
||||
"\n",
|
||||
"There are two base cases: two empty lists or one empty list, the recursive branch is taken only if both lists at non-empty.\n",
|
||||
"There are two base cases: two empty lists or one empty list, the recursive branch is taken only if both lists are non-empty.\n",
|
||||
"\n",
|
||||
" bool [a ...] [b ...] P\n",
|
||||
"\n",
|
||||
|
|
@ -955,7 +955,7 @@
|
|||
" carry [n ...] add-carry-to-digits\n",
|
||||
" carry [n ...] [_actd_P] [_actd_THEN] [_actd_R0] [_actd_R1] genrec\n",
|
||||
"\n",
|
||||
"The predicate is the carry flag itself inverted, but when we recur we need to check if the list is non-empty because it will eventually be empty or the carry flag will be false:\n",
|
||||
"The predicate is the carry flag itself inverted (but when we recur we will need to check if the list is non-empty because it may eventually be empty):\n",
|
||||
"\n",
|
||||
" _actd_P ≡ pop not\n",
|
||||
"\n",
|
||||
|
|
@ -992,52 +992,22 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "379d88db",
|
||||
"id": "d5898c6a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"If it's empty...\n",
|
||||
"\n",
|
||||
" true [] R0.else [add-carry-to-digits] R1\n",
|
||||
" ----------------------------------------------\n",
|
||||
" false [1] [add-carry-to-digits] R1\n",
|
||||
"\n",
|
||||
" R0.else ≡ 1 swons popd false swap"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "9f1e5b30",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"If it's not empty...\n",
|
||||
"\n",
|
||||
" true [a ...] R0.then [add-carry-to-digits] R1\n",
|
||||
" -------------------------------------------------------------\n",
|
||||
" true 0 a add-with-carry [...1] [add-carry-to-digits] R1\n",
|
||||
" -------------------------------------------------------------\n",
|
||||
" (a+1) carry [...1] [add-carry-to-digits] R1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d5898c6a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Ah ha!? How to get that `(a+1)` back into the list!?\n",
|
||||
"\n",
|
||||
"If it's empty...\n",
|
||||
"\n",
|
||||
" true [] R0.else [add-carry-to-digits] R1\n",
|
||||
" ------------------------------------------------\n",
|
||||
" 1 false [] [add-carry-to-digits] i cons\n",
|
||||
" 1 false [] [add-carry-to-digits] i cons\n",
|
||||
"\n",
|
||||
"and\n",
|
||||
"\n",
|
||||
" true [a ...] R0.then [add-carry-to-digits] i cons\n",
|
||||
" -------------------------------------------------------------\n",
|
||||
" true 0 a add-with-carry [...1] [add-carry-to-digits] i cons\n",
|
||||
" -------------------------------------------------------------\n",
|
||||
" (a+1) carry [...1] [add-carry-to-digits] i cons"
|
||||
" true [a ...] R0.then [add-carry-to-digits] i cons\n",
|
||||
" ----------------------------------------------------------------\n",
|
||||
" true 0 a add-with-carry [...] [add-carry-to-digits] i cons\n",
|
||||
" ----------------------------------------------------------------\n",
|
||||
" (a+1) carry [...] [add-carry-to-digits] i cons"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -1546,6 +1516,46 @@
|
|||
"source": [
|
||||
"Bitchin'"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f2b707c1",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Appendix: Source Code\n",
|
||||
"\n",
|
||||
" base 2147483648\n",
|
||||
" ditch-empty-list [bool] [popd] [pop] ifte\n",
|
||||
" bool_to_int [0] [1] branch\n",
|
||||
" uncons-two [uncons] ii swapd\n",
|
||||
"\n",
|
||||
" add-with-carry _a0 _a1\n",
|
||||
" _a0 [bool_to_int] dipd + +\n",
|
||||
" _a1 base [mod] [>=] clop\n",
|
||||
"\n",
|
||||
" add-carry-to-digits [pop not] [popd] [_actd_R0] [i cons] genrec\n",
|
||||
" _actd_R0 [bool] [_actd_R0.then] [_actd_R0.else] ifte\n",
|
||||
" _actd_R0.else popd 1 false rolldown\n",
|
||||
" _actd_R0.then 0 swap uncons [add-with-carry] dip\n",
|
||||
"\n",
|
||||
" add-digits initial-carry add-digits'\n",
|
||||
" initial-carry false rollup\n",
|
||||
" add-digits' [P] [THEN] [R0] [i cons] genrec\n",
|
||||
" P [bool] ii & not\n",
|
||||
" THEN [P'] [THEN'] [ELSE] ifte\n",
|
||||
" R0 uncons-two [add-with-carry] dipd\n",
|
||||
" P' [bool] ii |\n",
|
||||
" THEN' ditch-empty-list add-carry-to-digits\n",
|
||||
" ELSE pop swap [] [1 swons] branch\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "84affe68",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue