Update some of the docs.

This commit is contained in:
Simon Forman
2020-05-20 19:15:47 -07:00
parent 6a6b63bf62
commit ffabda0407
60 changed files with 5182 additions and 5853 deletions
+110 -370
View File
@@ -29,11 +29,11 @@
"name": "stdout",
"output_type": "stream",
"text": [
" . 23 sqr\n",
" 23 . sqr\n",
" 23 . dup mul\n",
"23 23 . mul\n",
" 529 . \n"
" 23 sqr\n",
" 23 sqr\n",
" 23 dup mul\n",
"23 23 mul\n",
" 529 \n"
]
}
],
@@ -89,9 +89,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
" . 23 sqr\n",
" 23 . sqr\n",
"529 . \n"
" 23 sqr\n",
" 23 sqr\n",
"529 \n"
]
}
],
@@ -131,7 +131,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 10,
"metadata": {},
"outputs": [
{
@@ -145,7 +145,7 @@
}
],
"source": [
"print compile_joy_definition(old_sqr)"
"print(compile_joy_definition(old_sqr))"
]
},
{
@@ -159,7 +159,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
@@ -168,7 +168,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
@@ -186,7 +186,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
@@ -214,9 +214,21 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 14,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'joy.utils.types'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-14-d5ef3c7560be>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mjoy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mutils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtypes\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mcompile_\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdoc_from_stack_effect\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minfer_string\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mjoy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlibrary\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mSimpleFunctionWrapper\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'joy.utils.types'"
]
}
],
"source": [
"from joy.utils.types import compile_, doc_from_stack_effect, infer_string\n",
"from joy.library import SimpleFunctionWrapper"
@@ -224,7 +236,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -240,17 +252,9 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(a2 a1 -- a1 a2 a1 a2 a2)\n"
]
}
],
"outputs": [],
"source": [
"for fi, fo in stack_effects:\n",
" print doc_from_stack_effect(fi, fo)"
@@ -258,7 +262,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -274,34 +278,27 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"def foo(stack):\n",
" \"\"\"\n",
" ::\n",
"\n",
" (a2 a1 -- a1 a2 a1 a2 a2)\n",
"\n",
" \"\"\"\n",
" (a1, (a2, s1)) = stack\n",
" return (a2, (a2, (a1, (a2, (a1, s1)))))\n"
]
}
],
"outputs": [],
"source": [
"print source"
]
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-9-1a7e90bf2d7b>, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-9-1a7e90bf2d7b>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m exec compile(source, '__main__', 'single')\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"exec compile(source, '__main__', 'single')\n",
"\n",
@@ -310,20 +307,9 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" . 23 18 foo\n",
" 23 . 18 foo\n",
" 23 18 . foo\n",
"18 23 18 23 23 . \n"
]
}
],
"outputs": [],
"source": [
"V('23 18 foo')"
]
@@ -351,7 +337,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -360,17 +346,9 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[a b c d] e a [f]] [[a e c d]]\n"
]
}
],
"outputs": [],
"source": [
"Ein = '[a b c d] e a [f]' # The terms should be reversed here but I don't realize that until later.\n",
"Eout = '[a e c d]'\n",
@@ -381,7 +359,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -390,38 +368,18 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(((a, (b, (c, (d, ())))), (e, (a, ((f, ()), ())))),\n",
" ((a, (e, (c, (d, ())))), ()))"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"fi, fo"
]
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[a1 a2 a3 a4] a5 a6 a7] [[a1 a5 a3 a4]]\n"
]
}
],
"outputs": [],
"source": [
"Ein = '[a1 a2 a3 a4] a5 a6 a7'\n",
"Eout = '[a1 a5 a3 a4]'\n",
@@ -432,7 +390,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -441,49 +399,18 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(((a1, (a2, (a3, (a4, ())))), (a5, (a6, (a7, ())))),\n",
" ((a1, (a5, (a3, (a4, ())))), ()))"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"fi, fo"
]
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'a1': a1,\n",
" 'a2': a2,\n",
" 'a3': a3,\n",
" 'a4': a4,\n",
" 'a5': a5,\n",
" 'a6': a6,\n",
" 'a7': a7,\n",
" 's0': s0,\n",
" 's1': s1}"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"def type_vars():\n",
" from joy.library import a1, a2, a3, a4, a5, a6, a7, s0, s1\n",
@@ -495,7 +422,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -504,17 +431,9 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(... a7 a6 a5 [a1 a2 a3 a4 ] -- ... [a1 a5 a3 a4 ])\n"
]
}
],
"outputs": [],
"source": [
"stack_effect = reify(tv, (fi, fo))\n",
"print doc_from_stack_effect(*stack_effect)"
@@ -522,17 +441,9 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(((a1, (a2, (a3, (a4, ())))), (a5, (a6, (a7, ())))), ((a1, (a5, (a3, (a4, ())))), ()))\n"
]
}
],
"outputs": [],
"source": [
"print stack_effect"
]
@@ -546,7 +457,7 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -562,17 +473,9 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(a7 a6 a5 [a1 a2 a3 a4 ...1] -- [a1 a5 a3 a4 ...1])\n"
]
}
],
"outputs": [],
"source": [
"print doc_from_stack_effect(*stack_effect)"
]
@@ -586,7 +489,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -602,42 +505,18 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(a7 a6 a5 [a1 a2 ...1] -- [a1 a5 ...1])\n"
]
}
],
"outputs": [],
"source": [
"print doc_from_stack_effect(*stack_effect)"
]
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"def Ee(stack):\n",
" \"\"\"\n",
" ::\n",
"\n",
" (a7 a6 a5 [a1 a2 ...1] -- [a1 a5 ...1])\n",
"\n",
" \"\"\"\n",
" ((a1, (a2, s1)), (a5, (a6, (a7, s0)))) = stack\n",
" return ((a1, (a5, s1)), s0)\n"
]
}
],
"outputs": [],
"source": [
"source = compile_('Ee', stack_effect)\n",
"print source"
@@ -652,7 +531,7 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -661,42 +540,18 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"([a1 a2 ...1] a5 a6 a7 -- [a1 a5 ...1])\n"
]
}
],
"outputs": [],
"source": [
"print doc_from_stack_effect(*stack_effect)"
]
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"def Ee(stack):\n",
" \"\"\"\n",
" ::\n",
"\n",
" ([a1 a2 ...1] a5 a6 a7 -- [a1 a5 ...1])\n",
"\n",
" \"\"\"\n",
" (a7, (a6, (a5, ((a1, (a2, s1)), s0)))) = stack\n",
" return ((a1, (a5, s1)), s0)\n"
]
}
],
"outputs": [],
"source": [
"source = compile_('Ee', stack_effect)\n",
"print source"
@@ -715,7 +570,7 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -725,24 +580,11 @@
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" . [a b c d] 1 2 [f] Ee\n",
" [a b c d] . 1 2 [f] Ee\n",
" [a b c d] 1 . 2 [f] Ee\n",
" [a b c d] 1 2 . [f] Ee\n",
"[a b c d] 1 2 [f] . Ee\n",
" [a 1 c d] . \n"
]
}
],
"outputs": [],
"source": [
"V('[a b c d] 1 2 [f] Ee')"
]
@@ -765,7 +607,7 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -785,17 +627,9 @@
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(n1 -- n2)\n"
]
}
],
"outputs": [],
"source": [
"stack_effects = infer_string('dup mul')\n",
"for fi, fo in stack_effects:\n",
@@ -811,7 +645,7 @@
},
{
"cell_type": "code",
"execution_count": 42,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -846,17 +680,9 @@
},
{
"cell_type": "code",
"execution_count": 43,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(n4 n3 n2 n1 -- n5)\n"
]
}
],
"outputs": [],
"source": [
"stack_effects = infer_string('mul mul sub')\n",
"for fi, fo in stack_effects:\n",
@@ -865,7 +691,7 @@
},
{
"cell_type": "code",
"execution_count": 44,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -896,17 +722,9 @@
},
{
"cell_type": "code",
"execution_count": 45,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(a2 a1 -- a1 a2 a1)\n"
]
}
],
"outputs": [],
"source": [
"stack_effects = infer_string('tuck')\n",
"for fi, fo in stack_effects:\n",
@@ -936,7 +754,7 @@
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -945,7 +763,7 @@
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -967,7 +785,7 @@
},
{
"cell_type": "code",
"execution_count": 80,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -992,7 +810,7 @@
},
{
"cell_type": "code",
"execution_count": 64,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -1023,7 +841,7 @@
},
{
"cell_type": "code",
"execution_count": 50,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -1092,7 +910,7 @@
},
{
"cell_type": "code",
"execution_count": 69,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -1102,18 +920,9 @@
},
{
"cell_type": "code",
"execution_count": 74,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"<ipython-input-74-a6ea700b09d9>:1: SyntaxWarning: import * only allowed at module level\n",
" def import_yin():\n"
]
}
],
"outputs": [],
"source": [
"def import_yin():\n",
" from joy.utils.generated_library import *\n",
@@ -1139,44 +948,18 @@
},
{
"cell_type": "code",
"execution_count": 75,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"def mul_(stack):\n",
" (a31, (a32, stack)) = stack\n",
" a33 = mul(a32, a31)\n",
" stack = (a33, stack)\n",
" return stack\n",
"\n"
]
}
],
"outputs": [],
"source": [
"print compile_yinyang('mul_', (names(), (names(), (mul, ()))))"
]
},
{
"cell_type": "code",
"execution_count": 76,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"def sqr(stack):\n",
" (a34, stack) = stack\n",
" a35 = mul(a34, a34)\n",
" stack = (a35, stack)\n",
" return stack\n",
"\n"
]
}
],
"outputs": [],
"source": [
"e = (names(), (dup, (mul, ())))\n",
"print compile_yinyang('sqr', e)"
@@ -1184,25 +967,11 @@
},
{
"cell_type": "code",
"execution_count": 77,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"def foo(stack):\n",
" (a36, (a37, stack)) = stack\n",
" a38 = sub(a37, a36)\n",
" a39 = mul(a38, a36)\n",
" stack = (a39, stack)\n",
" return stack\n",
"\n"
]
}
],
"outputs": [],
"source": [
"e = (names(), (dup, (names(), (sub, (mul, ())))))\n",
"print compile_yinyang('foo', e)"
@@ -1210,23 +979,9 @@
},
{
"cell_type": "code",
"execution_count": 78,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"def bar(stack):\n",
" (a40, (a41, stack)) = stack\n",
" a42 = mul(a41, a40)\n",
" a43 = sub(a42, a42)\n",
" stack = (a43, (a43, stack))\n",
" return stack\n",
"\n"
]
}
],
"outputs": [],
"source": [
"e = (names(), (names(), (mul, (dup, (sub, (dup, ()))))))\n",
"print compile_yinyang('bar', e)"
@@ -1234,24 +989,9 @@
},
{
"cell_type": "code",
"execution_count": 79,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"def to_the_fifth_power(stack):\n",
" (a44, stack) = stack\n",
" a45 = mul(a44, a44)\n",
" a46 = mul(a45, a45)\n",
" a47 = mul(a46, a44)\n",
" stack = (a47, stack)\n",
" return stack\n",
"\n"
]
}
],
"outputs": [],
"source": [
"e = (names(), (dup, (dup, (mul, (dup, (mul, (mul, ())))))))\n",
"print compile_yinyang('to_the_fifth_power', e)"
@@ -1295,14 +1035,14 @@
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.15"
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,