diff --git a/docs/0._This_Implementation_of_Joy_in_Python.ipynb b/docs/0._This_Implementation_of_Joy_in_Python.ipynb index 125137f..6f203aa 100644 --- a/docs/0._This_Implementation_of_Joy_in_Python.ipynb +++ b/docs/0._This_Implementation_of_Joy_in_Python.ipynb @@ -67,57 +67,56 @@ "name": "stdout", "output_type": "stream", "text": [ - "§ Stack\n", + "When talking about Joy we use the terms \"stack\", \"quote\", \"sequence\",\n", + "\"list\", and others to mean the same thing: a simple linear datatype that\n", + "permits certain operations such as iterating and pushing and popping\n", + "values from (at least) one end.\n", "\n", + "There is no \"Stack\" Python class, instead we use the `cons list`_, a \n", + "venerable two-tuple recursive sequence datastructure, where the\n", + "empty tuple ``()`` is the empty stack and ``(head, rest)`` gives the recursive\n", + "form of a stack with one or more items on it::\n", "\n", - "When talking about Joy we use the terms \"stack\", \"list\", \"sequence\" and\n", - "\"aggregate\" to mean the same thing: a simple datatype that permits\n", - "certain operations such as iterating and pushing and popping values from\n", - "(at least) one end.\n", + " stack := () | (item, stack)\n", "\n", - "We use the venerable two-tuple recursive form of sequences where the\n", - "empty tuple () is the empty stack and (head, rest) gives the recursive\n", - "form of a stack with one or more items on it.\n", + "Putting some numbers onto a stack::\n", "\n", - " ()\n", - " (1, ())\n", - " (2, (1, ()))\n", - " (3, (2, (1, ())))\n", - " ...\n", - "\n", - "And so on.\n", - "\n", - "\n", - "We have two very simple functions to build up a stack from a Python\n", - "iterable and also to iterate through a stack and yield its items\n", - "one-by-one in order, and two functions to generate string representations\n", - "of stacks:\n", - "\n", - " list_to_stack()\n", - "\n", - " iter_stack()\n", - "\n", - " expression_to_string() (prints left-to-right)\n", - "\n", - " stack_to_string() (prints right-to-left)\n", - "\n", - "\n", - "A word about the stack data structure.\n", + " ()\n", + " (1, ())\n", + " (2, (1, ()))\n", + " (3, (2, (1, ())))\n", + " ...\n", "\n", "Python has very nice \"tuple packing and unpacking\" in its syntax which\n", "means we can directly \"unpack\" the expected arguments to a Joy function.\n", "\n", - "For example:\n", + "For example::\n", "\n", - " def dup(stack):\n", - " head, tail = stack\n", - " return head, (head, tail)\n", + " def dup((head, tail)):\n", + " return head, (head, tail)\n", "\n", "We replace the argument \"stack\" by the expected structure of the stack,\n", - "in this case \"(head, tail)\", and Python takes care of de-structuring the\n", - "incoming argument and assigning values to the names. Note that Python\n", + "in this case \"(head, tail)\", and Python takes care of unpacking the\n", + "incoming tuple and assigning values to the names. (Note that Python\n", "syntax doesn't require parentheses around tuples used in expressions\n", - "where they would be redundant.\n" + "where they would be redundant.)\n", + "\n", + "Unfortunately, the Sphinx documentation generator, which is used to generate this\n", + "web page, doesn't handle tuples in the function parameters. And in Python 3, this\n", + "syntax was removed entirely. Instead you would have to write::\n", + "\n", + " def dup(stack):\n", + " head, tail = stack\n", + " return head, (head, tail)\n", + "\n", + "\n", + "We have two very simple functions, one to build up a stack from a Python\n", + "iterable and another to iterate through a stack and yield its items\n", + "one-by-one in order. There are also two functions to generate string representations\n", + "of stacks. They only differ in that one prints the terms in stack from left-to-right while the other prints from right-to-left. In both functions *internal stacks* are\n", + "printed left-to-right. These functions are written to support :doc:`../pretty`.\n", + "\n", + ".. _cons list: https://en.wikipedia.org/wiki/Cons#Lists\n" ] } ], @@ -237,22 +236,36 @@ "output_type": "stream", "text": [ "def joy(stack, expression, dictionary, viewer=None):\n", - " '''\n", - " Evaluate the Joy expression on the stack.\n", - " '''\n", - " while expression:\n", + "\t'''Evaluate a Joy expression on a stack.\n", "\n", - " if viewer: viewer(stack, expression)\n", + "\tThis function iterates through a sequence of terms which are either\n", + "\tliterals (strings, numbers, sequences of terms) or function symbols.\n", + "\tLiterals are put onto the stack and functions are looked up in the\n", + "\tdisctionary and executed.\n", "\n", - " term, expression = expression\n", - " if isinstance(term, Symbol):\n", - " term = dictionary[term]\n", - " stack, expression, dictionary = term(stack, expression, dictionary)\n", - " else:\n", - " stack = term, stack\n", + "\tThe viewer is a function that is called with the stack and expression\n", + "\ton every iteration, its return value is ignored.\n", "\n", - " if viewer: viewer(stack, expression)\n", - " return stack, expression, dictionary\n", + "\t:param stack stack: The stack.\n", + "\t:param stack expression: The expression to evaluate.\n", + "\t:param dict dictionary: A ``dict`` mapping names to Joy functions.\n", + "\t:param function viewer: Optional viewer function.\n", + "\t:rtype: (stack, (), dictionary)\n", + "\n", + "\t'''\n", + "\twhile expression:\n", + "\n", + "\t\tif viewer: viewer(stack, expression)\n", + "\n", + "\t\tterm, expression = expression\n", + "\t\tif isinstance(term, Symbol):\n", + "\t\t\tterm = dictionary[term]\n", + "\t\t\tstack, expression, dictionary = term(stack, expression, dictionary)\n", + "\t\telse:\n", + "\t\t\tstack = term, stack\n", + "\n", + "\tif viewer: viewer(stack, expression)\n", + "\treturn stack, expression, dictionary\n", "\n" ] } @@ -304,19 +317,22 @@ "name": "stdout", "output_type": "stream", "text": [ - "§ Converting text to a joy expression.\n", + "This module exports a single function for converting text to a joy\n", + "expression as well as a single Symbol class and a single Exception type.\n", "\n", - "This module exports a single function:\n", + "The Symbol string class is used by the interpreter to recognize literals\n", + "by the fact that they are not Symbol objects.\n", "\n", - " text_to_expression(text)\n", + "A crude grammar::\n", "\n", - "As well as a single Symbol class and a single Exception type:\n", + " joy = term*\n", + " term = int | float | string | '[' joy ']' | symbol\n", "\n", - " ParseError\n", - "\n", - "When supplied with a string this function returns a Python datastructure\n", - "that represents the Joy datastructure described by the text expression.\n", - "Any unbalanced square brackets will raise a ParseError.\n" + "A Joy expression is a sequence of zero or more terms. A term is a\n", + "literal value (integer, float, string, or Joy expression) or a function\n", + "symbol. Function symbols are unquoted strings and cannot contain square\n", + "brackets. Terms must be separated by blanks, which can be omitted\n", + "around square brackets.\n" ] } ], @@ -343,27 +359,27 @@ "output_type": "stream", "text": [ "def _parse(tokens):\n", - " '''\n", - " Return a stack/list expression of the tokens.\n", - " '''\n", - " frame = []\n", - " stack = []\n", - " for tok in tokens:\n", - " if tok == '[':\n", - " stack.append(frame)\n", - " frame = []\n", - " stack[-1].append(frame)\n", - " elif tok == ']':\n", - " try:\n", - " frame = stack.pop()\n", - " except IndexError:\n", - " raise ParseError('One or more extra closing brackets.')\n", - " frame[-1] = list_to_stack(frame[-1])\n", - " else:\n", - " frame.append(tok)\n", - " if stack:\n", - " raise ParseError('One or more unclosed brackets.')\n", - " return list_to_stack(frame)\n", + "\t'''\n", + "\tReturn a stack/list expression of the tokens.\n", + "\t'''\n", + "\tframe = []\n", + "\tstack = []\n", + "\tfor tok in tokens:\n", + "\t\tif tok == '[':\n", + "\t\t\tstack.append(frame)\n", + "\t\t\tframe = []\n", + "\t\t\tstack[-1].append(frame)\n", + "\t\telif tok == ']':\n", + "\t\t\ttry:\n", + "\t\t\t\tframe = stack.pop()\n", + "\t\t\texcept IndexError:\n", + "\t\t\t\traise ParseError('Extra closing bracket.')\n", + "\t\t\tframe[-1] = list_to_stack(frame[-1])\n", + "\t\telse:\n", + "\t\t\tframe.append(tok)\n", + "\tif stack:\n", + "\t\traise ParseError('Unclosed bracket.')\n", + "\treturn list_to_stack(frame)\n", "\n" ] } @@ -498,7 +514,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "!= % & * *fraction *fraction0 + ++ - -- / < << <= <> = > >= >> ? ^ add anamorphism and app1 app2 app3 average b binary branch choice clear cleave concat cons dinfrirst dip dipd dipdd disenstacken div down_to_zero dudipd dup dupd dupdip enstacken eq first flatten floordiv gcd ge genrec getitem gt help i id ifte infra le least_fraction loop lshift lt map min mod modulus mul ne neg not nullary or over pam parse pm pop popd popdd popop pow pred primrec product quoted range range_to_zero rem remainder remove rest reverse roll< roll> rolldown rollup rshift run second select sharing shunt size sqr sqrt stack step sub succ sum swaack swap swoncat swons ternary third times truediv truthy tuck unary uncons unit unquoted unstack void warranty while words x xor zip •\n" + "!= % & * *fraction *fraction0 + ++ - -- / // /floor < << <= <> = > >= >> ? ^ _Tree_add_Ee _Tree_delete_R0 _Tree_delete_clear_stuff _Tree_get_E abs add anamorphism and app1 app2 app3 at average b binary bool branch ccons choice clear cleave cmp codireco concat cond cons dinfrirst dip dipd dipdd disenstacken divmod down_to_zero drop dup dupd dupdd dupdip dupdipd enstacken eq first first_two flatten floor floordiv fork fourth gcd ge genrec getitem gt help i id ifte ii infer infra inscribe le least_fraction loop lshift lt make_generator map max min mod modulus mul ne neg not nullary of or over pam parse pick pm pop popd popdd popop popopd popopdd pow pred primrec product quoted range range_to_zero rem remainder remove rest reverse roll< roll> rolldown rollup round rrest rshift run second select sharing shunt size sort sqr sqrt stack step step_zero stuncons stununcons sub succ sum swaack swap swons take ternary third times truediv truthy tuck unary uncons unique unit unquoted unstack unswons void warranty while words x xor zip •\n" ] } ], @@ -524,10 +540,24 @@ "name": "stdout", "output_type": "stream", "text": [ + "@inscribe\n", + "@combinator_effect(_COMB_NUMS(), a1, s1)\n", + "@FunctionWrapper\n", "def dip(stack, expression, dictionary):\n", - " (quote, (x, stack)) = stack\n", - " expression = x, expression\n", - " return stack, pushback(quote, expression), dictionary\n", + "\t'''\n", + "\tThe dip combinator expects a quoted program on the stack and below it\n", + "\tsome item, it hoists the item into the expression and runs the program\n", + "\ton the rest of the stack.\n", + "\t::\n", + "\n", + "\t\t\t ... x [Q] dip\n", + "\t\t-------------------\n", + "\t\t\t\t ... Q x\n", + "\n", + "\t'''\n", + "\t(quote, (x, stack)) = stack\n", + "\texpression = (x, expression)\n", + "\treturn stack, concat(quote, expression), dictionary\n", "\n" ] } @@ -552,28 +582,26 @@ "name": "stdout", "output_type": "stream", "text": [ - "second == rest first\n", - "third == rest rest first\n", + "ii == [dip] dupdip i\n", + "of == swap at\n", "product == 1 swap [*] step\n", - "swons == swap cons\n", - "swoncat == swap concat\n", "flatten == [] swap [concat] step\n", - "unit == [] cons\n", "quoted == [unit] dip\n", "unquoted == [i] dip\n", "enstacken == stack [clear] dip\n", - "disenstacken == ? [uncons ?] loop pop\n", "? == dup truthy\n", + "disenstacken == ? [uncons ?] loop pop\n", "dinfrirst == dip infra first\n", "nullary == [stack] dinfrirst\n", - "unary == [stack [pop] dip] dinfrirst\n", - "binary == [stack [popop] dip] dinfrirst\n", - "ternary == [stack [popop pop] dip] dinfrirst\n", + "unary == nullary popd\n", + "binary == nullary [popop] dip\n", + "ternary == unary [popop] dip\n", "pam == [i] map\n", "run == [] swap infra\n", "sqr == dup mul\n", "size == 0 swap [pop ++] step\n", - "cleave == [i] app2 [popd] dip\n", + "fork == [i] app2\n", + "cleave == fork [popd] dip\n", "average == [sum 1.0 *] [size] cleave /\n", "gcd == 1 [tuck modulus dup 0 >] loop pop\n", "least_fraction == dup [gcd] infra [div] concat map\n", @@ -584,8 +612,12 @@ "anamorphism == [pop []] swap [dip swons] genrec\n", "range == [0 <=] [1 - dup] anamorphism\n", "while == swap [nullary] cons dup dipd concat loop\n", - "dudipd == dup dipd\n", + "dupdipd == dup dipd\n", "primrec == [i] genrec\n", + "step_zero == 0 roll> step\n", + "codireco == cons dip rest cons\n", + "make_generator == [codireco] ccons\n", + "ifte == [nullary not] dipd branch\n", "\n" ] } diff --git a/docs/1._Basic_Use_of_Joy_in_a_Notebook.ipynb b/docs/1._Basic_Use_of_Joy_in_a_Notebook.ipynb index 3b99e49..de6487b 100644 --- a/docs/1._Basic_Use_of_Joy_in_a_Notebook.ipynb +++ b/docs/1._Basic_Use_of_Joy_in_a_Notebook.ipynb @@ -214,6 +214,13 @@ "source": [ "V('96 27 gcd')" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/docs/2._Library_Examples.ipynb b/docs/2._Library_Examples.ipynb index 1349eb4..3d4d739 100644 --- a/docs/2._Library_Examples.ipynb +++ b/docs/2._Library_Examples.ipynb @@ -461,10 +461,17 @@ }, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "[4 5 6 1 2 3]\n" + "ename": "KeyError", + "evalue": "swoncat", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mJ\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'[1 2 3] [4 5 6] swoncat'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m/home/sforman/Desktop/ArchLayer/System/source/Thun/docs/notebook_preamble.py\u001b[0m in \u001b[0;36mJ\u001b[0;34m(text, stack, dictionary)\u001b[0m\n\u001b[1;32m 30\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 31\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mJ\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstack\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mS\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdictionary\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mD\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 32\u001b[0;31m \u001b[0;32mprint\u001b[0m \u001b[0mstack_to_string\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstack\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdictionary\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 33\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/home/sforman/Desktop/ArchLayer/System/source/Thun/venv/local/lib/python2.7/site-packages/joy/joy.pyc\u001b[0m in \u001b[0;36mrun\u001b[0;34m(text, stack, dictionary, viewer)\u001b[0m\n\u001b[1;32m 77\u001b[0m \t'''\n\u001b[1;32m 78\u001b[0m \u001b[0mexpression\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtext_to_expression\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 79\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mjoy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstack\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexpression\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdictionary\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mviewer\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 80\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 81\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/home/sforman/Desktop/ArchLayer/System/source/Thun/venv/local/lib/python2.7/site-packages/joy/joy.pyc\u001b[0m in \u001b[0;36mjoy\u001b[0;34m(stack, expression, dictionary, viewer)\u001b[0m\n\u001b[1;32m 56\u001b[0m \u001b[0mterm\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexpression\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mexpression\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 57\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mterm\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSymbol\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 58\u001b[0;31m \u001b[0mterm\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdictionary\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mterm\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 59\u001b[0m \u001b[0mstack\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexpression\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdictionary\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mterm\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstack\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexpression\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdictionary\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 60\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyError\u001b[0m: swoncat" ] } ], @@ -474,19 +481,11 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[6 5 4 1 2 3]\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 3] [4 5 6] shunt')" ] @@ -500,51 +499,27 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1 2 3]\n" - ] - } - ], + "outputs": [], "source": [ "J('1 [2 3] cons')" ] }, { "cell_type": "code", - "execution_count": 25, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1 2 3]\n" - ] - } - ], + "outputs": [], "source": [ "J('[2 3] 1 swons')" ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 [2 3]\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 3] uncons')" ] @@ -558,70 +533,38 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 3 4] first')" ] }, { "cell_type": "code", - "execution_count": 28, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 3 4] second')" ] }, { "cell_type": "code", - "execution_count": 29, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 3 4] third')" ] }, { "cell_type": "code", - "execution_count": 30, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[2 3 4]\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 3 4] rest')" ] @@ -635,17 +578,9 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1 2 [3] 4 5 6]\n" - ] - } - ], + "outputs": [], "source": [ "J('[[1] [2 [3] 4] [5 6]] flatten')" ] @@ -661,87 +596,47 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "12\n" - ] - } - ], + "outputs": [], "source": [ "J('[10 11 12 13 14] 2 getitem')" ] }, { "cell_type": "code", - "execution_count": 33, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 3 4] 0 at')" ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3\n" - ] - } - ], + "outputs": [], "source": [ "J('2 [1 2 3 4] of')" ] }, { "cell_type": "code", - "execution_count": 35, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[3 4]\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 3 4] 2 drop')" ] }, { "cell_type": "code", - "execution_count": 36, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[2 1]\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 3 4] 2 take') # reverses the order" ] @@ -762,17 +657,9 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[2 3 1 4]\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 3 1 4] 1 remove')" ] @@ -786,19 +673,11 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[4 3 2 1]\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 3 4] reverse')" ] @@ -812,19 +691,11 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "4\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 1 1 1] size')" ] @@ -839,19 +710,11 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "6 5 4 [3 2 1]\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 3 [4 5 6] swaack')" ] @@ -865,72 +728,40 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "9\n" - ] - } - ], + "outputs": [], "source": [ "J('23 9 1 choice')" ] }, { "cell_type": "code", - "execution_count": 42, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "23\n" - ] - } - ], + "outputs": [], "source": [ "J('23 9 0 choice')" ] }, { "cell_type": "code", - "execution_count": 43, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "9\n" - ] - } - ], + "outputs": [], "source": [ "J('[23 9 7] 1 select') # select is basically getitem, should retire it?" ] }, { "cell_type": "code", - "execution_count": 44, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "23\n" - ] - } - ], + "outputs": [], "source": [ "J('[23 9 7] 0 select')" ] @@ -944,34 +775,18 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[6 1] [5 2] [4 3]]\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 3] [6 5 4] zip')" ] }, { "cell_type": "code", - "execution_count": 46, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[7 7 7]\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 3] [6 5 4] zip [sum] map')" ] @@ -992,17 +807,9 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "32\n" - ] - } - ], + "outputs": [], "source": [ "J('23 9 +')" ] @@ -1016,17 +823,9 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "14\n" - ] - } - ], + "outputs": [], "source": [ "J('23 9 -')" ] @@ -1040,17 +839,9 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "207\n" - ] - } - ], + "outputs": [], "source": [ "J('23 9 *')" ] @@ -1064,114 +855,66 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2.5555555555555554\n" - ] - } - ], + "outputs": [], "source": [ "J('23 9 /')" ] }, { "cell_type": "code", - "execution_count": 51, + "execution_count": null, "metadata": { "scrolled": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-2.5555555555555554\n" - ] - } - ], + "outputs": [], "source": [ "J('23 -9 truediv')" ] }, { "cell_type": "code", - "execution_count": 52, + "execution_count": null, "metadata": { "scrolled": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2\n" - ] - } - ], + "outputs": [], "source": [ "J('23 9 div')" ] }, { "cell_type": "code", - "execution_count": 53, + "execution_count": null, "metadata": { "scrolled": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2\n" - ] - } - ], + "outputs": [], "source": [ "J('23 9 floordiv')" ] }, { "cell_type": "code", - "execution_count": 54, + "execution_count": null, "metadata": { "scrolled": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-3\n" - ] - } - ], + "outputs": [], "source": [ "J('23 -9 div')" ] }, { "cell_type": "code", - "execution_count": 55, + "execution_count": null, "metadata": { "scrolled": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-3\n" - ] - } - ], + "outputs": [], "source": [ "J('23 -9 floordiv')" ] @@ -1185,17 +928,9 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "5\n" - ] - } - ], + "outputs": [], "source": [ "J('23 9 %')" ] @@ -1209,17 +944,9 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-23 5\n" - ] - } - ], + "outputs": [], "source": [ "J('23 neg -5 neg')" ] @@ -1233,17 +960,9 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1024\n" - ] - } - ], + "outputs": [], "source": [ "J('2 10 pow')" ] @@ -1257,34 +976,18 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "529\n" - ] - } - ], + "outputs": [], "source": [ "J('23 sqr')" ] }, { "cell_type": "code", - "execution_count": 60, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "4.795831523312719\n" - ] - } - ], + "outputs": [], "source": [ "J('23 sqrt')" ] @@ -1298,36 +1001,20 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2\n" - ] - } - ], + "outputs": [], "source": [ "J('1 ++')" ] }, { "cell_type": "code", - "execution_count": 62, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0\n" - ] - } - ], + "outputs": [], "source": [ "J('1 --')" ] @@ -1341,34 +1028,18 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "16\n" - ] - } - ], + "outputs": [], "source": [ "J('8 1 <<')" ] }, { "cell_type": "code", - "execution_count": 64, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "4\n" - ] - } - ], + "outputs": [], "source": [ "J('8 1 >>')" ] @@ -1382,17 +1053,9 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2.75\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 3 5] average')" ] @@ -1406,51 +1069,27 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[4 3 2 1 0]\n" - ] - } - ], + "outputs": [], "source": [ "J('5 range')" ] }, { "cell_type": "code", - "execution_count": 67, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[0 1 2 3 4 5]\n" - ] - } - ], + "outputs": [], "source": [ "J('5 range_to_zero')" ] }, { "cell_type": "code", - "execution_count": 68, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "5 4 3 2 1 0\n" - ] - } - ], + "outputs": [], "source": [ "J('5 down_to_zero')" ] @@ -1464,17 +1103,9 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "30\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 3 5] product')" ] @@ -1488,17 +1119,9 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "11\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 3 5] sum')" ] @@ -1512,17 +1135,9 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 3 5] min')" ] @@ -1536,17 +1151,9 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "15\n" - ] - } - ], + "outputs": [], "source": [ "J('45 30 gcd')" ] @@ -1561,34 +1168,18 @@ }, { "cell_type": "code", - "execution_count": 73, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[3 2]\n" - ] - } - ], + "outputs": [], "source": [ "J('[45 30] least_fraction')" ] }, { "cell_type": "code", - "execution_count": 74, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[23 12]\n" - ] - } - ], + "outputs": [], "source": [ "J('[23 12] least_fraction')" ] @@ -1610,51 +1201,27 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" - ] - } - ], + "outputs": [], "source": [ "J('23 truthy')" ] }, { "cell_type": "code", - "execution_count": 76, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "False\n" - ] - } - ], + "outputs": [], "source": [ "J('[] truthy') # Python semantics." ] }, { "cell_type": "code", - "execution_count": 77, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "False\n" - ] - } - ], + "outputs": [], "source": [ "J('0 truthy')" ] @@ -1668,55 +1235,27 @@ }, { "cell_type": "code", - "execution_count": 78, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " . 23 ?\n", - " 23 . ?\n", - " 23 . dup truthy\n", - " 23 23 . truthy\n", - "23 True . \n" - ] - } - ], + "outputs": [], "source": [ "V('23 ?')" ] }, { "cell_type": "code", - "execution_count": 79, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[] False\n" - ] - } - ], + "outputs": [], "source": [ "J('[] ?')" ] }, { "cell_type": "code", - "execution_count": 80, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0 False\n" - ] - } - ], + "outputs": [], "source": [ "J('0 ?')" ] @@ -1730,17 +1269,9 @@ }, { "cell_type": "code", - "execution_count": 81, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1\n" - ] - } - ], + "outputs": [], "source": [ "J('23 9 &')" ] @@ -1754,17 +1285,9 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" - ] - } - ], + "outputs": [], "source": [ "J('23 9 !=')" ] @@ -1792,34 +1315,18 @@ }, { "cell_type": "code", - "execution_count": 83, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0\n" - ] - } - ], + "outputs": [], "source": [ "J('1 1 ^')" ] }, { "cell_type": "code", - "execution_count": 84, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1\n" - ] - } - ], + "outputs": [], "source": [ "J('1 0 ^')" ] @@ -1840,20 +1347,11 @@ }, { "cell_type": "code", - "execution_count": 85, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Accepts a quoted symbol on the top of the stack and prints its docs.\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "J('[help] help')" ] @@ -1867,37 +1365,20 @@ }, { "cell_type": "code", - "execution_count": 86, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Parse the string on the stack to a Joy expression.\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "J('[parse] help')" ] }, { "cell_type": "code", - "execution_count": 87, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 [2 [3] dup]\n" - ] - } - ], + "outputs": [], "source": [ "J('1 \"2 [3] dup\" parse')" ] @@ -1912,17 +1393,9 @@ }, { "cell_type": "code", - "execution_count": 88, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[5]\n" - ] - } - ], + "outputs": [], "source": [ "J('[1 2 dup + +] run')" ] @@ -1943,98 +1416,45 @@ }, { "cell_type": "code", - "execution_count": 89, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Given a quoted program on TOS and anything as the second stack item run\n", - "the program and replace the two args with the first result of the\n", - "program.\n", - "\n", - " ... x [Q] . app1\n", - " -----------------------------------\n", - " ... [x ...] [Q] . infra first\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "J('[app1] help')" ] }, { "cell_type": "code", - "execution_count": 90, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "10 160\n" - ] - } - ], + "outputs": [], "source": [ "J('10 4 [sqr *] app1')" ] }, { "cell_type": "code", - "execution_count": 91, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "10 90 160\n" - ] - } - ], + "outputs": [], "source": [ "J('10 3 4 [sqr *] app2')" ] }, { "cell_type": "code", - "execution_count": 92, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Like app1 with two items.\n", - "\n", - " ... y x [Q] . app2\n", - "-----------------------------------\n", - " ... [y ...] [Q] . infra first\n", - " [x ...] [Q] infra first\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "J('[app2] help')" ] }, { "cell_type": "code", - "execution_count": 93, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "10 40 90 160\n" - ] - } - ], + "outputs": [], "source": [ "J('10 2 3 4 [sqr *] app3')" ] @@ -2057,17 +1477,9 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[2 1 0]\n" - ] - } - ], + "outputs": [], "source": [ "J('3 [0 <=] [1 - dup] anamorphism')" ] @@ -2081,34 +1493,18 @@ }, { "cell_type": "code", - "execution_count": 95, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "12\n" - ] - } - ], + "outputs": [], "source": [ "J('3 4 1 [+] [*] branch')" ] }, { "cell_type": "code", - "execution_count": 96, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "7\n" - ] - } - ], + "outputs": [], "source": [ "J('3 4 0 [+] [*] branch')" ] @@ -2133,17 +1529,9 @@ }, { "cell_type": "code", - "execution_count": 97, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "10 12 8\n" - ] - } - ], + "outputs": [], "source": [ "J('10 2 [+] [-] cleave')" ] @@ -2157,51 +1545,27 @@ }, { "cell_type": "code", - "execution_count": 98, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 2 7 5\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 3 4 5 [+] dip')" ] }, { "cell_type": "code", - "execution_count": 99, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 5 4 5\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 3 4 5 [+] dipd')" ] }, { "cell_type": "code", - "execution_count": 100, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3 3 4 5\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 3 4 5 [+] dipdd')" ] @@ -2218,23 +1582,9 @@ }, { "cell_type": "code", - "execution_count": 101, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " . 23 [++] dupdip *\n", - " 23 . [++] dupdip *\n", - "23 [++] . dupdip *\n", - " 23 . ++ 23 *\n", - " 24 . 23 *\n", - " 24 23 . *\n", - " 552 . \n" - ] - } - ], + "outputs": [], "source": [ "V('23 [++] dupdip *') # N(N + 1)" ] @@ -2248,78 +1598,18 @@ }, { "cell_type": "code", - "execution_count": 102, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "General Recursion Combinator.\n", - "\n", - " [if] [then] [rec1] [rec2] genrec\n", - " ---------------------------------------------------------------------\n", - " [if] [then] [rec1 [[if] [then] [rec1] [rec2] genrec] rec2] ifte\n", - "\n", - "From \"Recursion Theory and Joy\" (j05cmp.html) by Manfred von Thun:\n", - "\"The genrec combinator takes four program parameters in addition to\n", - "whatever data parameters it needs. Fourth from the top is an if-part,\n", - "followed by a then-part. If the if-part yields true, then the then-part\n", - "is executed and the combinator terminates. The other two parameters are\n", - "the rec1-part and the rec2-part. If the if-part yields false, the\n", - "rec1-part is executed. Following that the four program parameters and\n", - "the combinator are again pushed onto the stack bundled up in a quoted\n", - "form. Then the rec2-part is executed, where it will find the bundled\n", - "form. Typically it will then execute the bundled form, either with i or\n", - "with app2, or some other combinator.\"\n", - "\n", - "The way to design one of these is to fix your base case [then] and the\n", - "test [if], and then treat rec1 and rec2 as an else-part \"sandwiching\"\n", - "a quotation of the whole function.\n", - "\n", - "For example, given a (general recursive) function 'F':\n", - "\n", - " F == [I] [T] [R1] [R2] genrec\n", - "\n", - "If the [I] if-part fails you must derive R1 and R2 from:\n", - "\n", - " ... R1 [F] R2\n", - "\n", - "Just set the stack arguments in front, and figure out what R1 and R2\n", - "have to do to apply the quoted [F] in the proper way. In effect, the\n", - "genrec combinator turns into an ifte combinator with a quoted copy of\n", - "the original definition in the else-part:\n", - "\n", - " F == [I] [T] [R1] [R2] genrec\n", - " == [I] [T] [R1 [F] R2] ifte\n", - "\n", - "(Primitive recursive functions are those where R2 == i.\n", - "\n", - " P == [I] [T] [R] primrec\n", - " == [I] [T] [R [P] i] ifte\n", - " == [I] [T] [R P] ifte\n", - ")\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "J('[genrec] help')" ] }, { "cell_type": "code", - "execution_count": 103, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "6\n" - ] - } - ], + "outputs": [], "source": [ "J('3 [1 <=] [] [dup --] [i *] genrec')" ] @@ -2333,26 +1623,11 @@ }, { "cell_type": "code", - "execution_count": 104, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " . 1 2 3 [+ +] i\n", - " 1 . 2 3 [+ +] i\n", - " 1 2 . 3 [+ +] i\n", - " 1 2 3 . [+ +] i\n", - "1 2 3 [+ +] . i\n", - " 1 2 3 . + +\n", - " 1 5 . +\n", - " 6 . \n" - ] - } - ], + "outputs": [], "source": [ "V('1 2 3 [+ +] i')" ] @@ -2367,34 +1642,18 @@ }, { "cell_type": "code", - "execution_count": 105, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 [1] [+] [*] ifte')" ] }, { "cell_type": "code", - "execution_count": 106, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 [0] [+] [*] ifte')" ] @@ -2408,27 +1667,9 @@ }, { "cell_type": "code", - "execution_count": 107, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " . 1 2 3 [4 5 6] [* +] infra\n", - " 1 . 2 3 [4 5 6] [* +] infra\n", - " 1 2 . 3 [4 5 6] [* +] infra\n", - " 1 2 3 . [4 5 6] [* +] infra\n", - " 1 2 3 [4 5 6] . [* +] infra\n", - "1 2 3 [4 5 6] [* +] . infra\n", - " 6 5 4 . * + [3 2 1] swaack\n", - " 6 20 . + [3 2 1] swaack\n", - " 26 . [3 2 1] swaack\n", - " 26 [3 2 1] . swaack\n", - " 1 2 3 [26] . \n" - ] - } - ], + "outputs": [], "source": [ "V('1 2 3 [4 5 6] [* +] infra')" ] @@ -2442,62 +1683,18 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Basic loop combinator.\n", - "\n", - " ... True [Q] loop\n", - "-----------------------\n", - " ... Q [Q] loop\n", - "\n", - " ... False [Q] loop\n", - "------------------------\n", - " ...\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "J('[loop] help')" ] }, { "cell_type": "code", - "execution_count": 109, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " . 3 dup [1 - dup] loop\n", - " 3 . dup [1 - dup] loop\n", - " 3 3 . [1 - dup] loop\n", - "3 3 [1 - dup] . loop\n", - " 3 . 1 - dup [1 - dup] loop\n", - " 3 1 . - dup [1 - dup] loop\n", - " 2 . dup [1 - dup] loop\n", - " 2 2 . [1 - dup] loop\n", - "2 2 [1 - dup] . loop\n", - " 2 . 1 - dup [1 - dup] loop\n", - " 2 1 . - dup [1 - dup] loop\n", - " 1 . dup [1 - dup] loop\n", - " 1 1 . [1 - dup] loop\n", - "1 1 [1 - dup] . loop\n", - " 1 . 1 - dup [1 - dup] loop\n", - " 1 1 . - dup [1 - dup] loop\n", - " 0 . dup [1 - dup] loop\n", - " 0 0 . [1 - dup] loop\n", - "0 0 [1 - dup] . loop\n", - " 0 . \n" - ] - } - ], + "outputs": [], "source": [ "V('3 dup [1 - dup] loop')" ] @@ -2511,34 +1708,18 @@ }, { "cell_type": "code", - "execution_count": 110, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "10 [10 20 30]\n" - ] - } - ], + "outputs": [], "source": [ "J('10 [1 2 3] [*] map')" ] }, { "cell_type": "code", - "execution_count": 111, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "10 5 [50 2.0 15 5]\n" - ] - } - ], + "outputs": [], "source": [ "J('10 5 [[*][/][+][-]] pam')" ] @@ -2553,68 +1734,36 @@ }, { "cell_type": "code", - "execution_count": 112, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 2 3 4 5 9\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 3 4 5 [+] nullary')" ] }, { "cell_type": "code", - "execution_count": 113, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 2 3 4 9\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 3 4 5 [+] unary')" ] }, { "cell_type": "code", - "execution_count": 114, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 2 3 9\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 3 4 5 [+] binary') # + has arity 2 so this is technically pointless..." ] }, { "cell_type": "code", - "execution_count": 115, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 2 9\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 3 4 5 [+] ternary')" ] @@ -2628,70 +1777,20 @@ }, { "cell_type": "code", - "execution_count": 116, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Run a quoted program on each item in a sequence.\n", - "\n", - " ... [] [Q] . step\n", - " -----------------------\n", - " ... .\n", - "\n", - "\n", - " ... [a] [Q] . step\n", - " ------------------------\n", - " ... a . Q\n", - "\n", - "\n", - " ... [a b c] [Q] . step\n", - "----------------------------------------\n", - " ... a . Q [b c] [Q] step\n", - "\n", - "The step combinator executes the quotation on each member of the list\n", - "on top of the stack.\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "J('[step] help')" ] }, { "cell_type": "code", - "execution_count": 117, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " . 0 [1 2 3] [+] step\n", - " 0 . [1 2 3] [+] step\n", - " 0 [1 2 3] . [+] step\n", - "0 [1 2 3] [+] . step\n", - " 0 1 [+] . i [2 3] [+] step\n", - " 0 1 . + [2 3] [+] step\n", - " 1 . [2 3] [+] step\n", - " 1 [2 3] . [+] step\n", - " 1 [2 3] [+] . step\n", - " 1 2 [+] . i [3] [+] step\n", - " 1 2 . + [3] [+] step\n", - " 3 . [3] [+] step\n", - " 3 [3] . [+] step\n", - " 3 [3] [+] . step\n", - " 3 3 [+] . i\n", - " 3 3 . +\n", - " 6 . \n" - ] - } - ], + "outputs": [], "source": [ "V('0 [1 2 3] [+] step')" ] @@ -2705,28 +1804,9 @@ }, { "cell_type": "code", - "execution_count": 118, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " . 3 2 1 2 [+] times\n", - " 3 . 2 1 2 [+] times\n", - " 3 2 . 1 2 [+] times\n", - " 3 2 1 . 2 [+] times\n", - " 3 2 1 2 . [+] times\n", - "3 2 1 2 [+] . times\n", - " 3 2 1 . + 1 [+] times\n", - " 3 3 . 1 [+] times\n", - " 3 3 1 . [+] times\n", - " 3 3 1 [+] . times\n", - " 3 3 . +\n", - " 6 . \n" - ] - } - ], + "outputs": [], "source": [ "V('3 2 1 2 [+] times')" ] @@ -2740,45 +1820,18 @@ }, { "cell_type": "code", - "execution_count": 119, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "b == [i] dip i\n", - "\n", - "... [P] [Q] b == ... [P] i [Q] i\n", - "... [P] [Q] b == ... P Q\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "J('[b] help')" ] }, { "cell_type": "code", - "execution_count": 120, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " . 1 2 [3] [4] b\n", - " 1 . 2 [3] [4] b\n", - " 1 2 . [3] [4] b\n", - " 1 2 [3] . [4] b\n", - "1 2 [3] [4] . b\n", - " 1 2 . 3 4\n", - " 1 2 3 . 4\n", - " 1 2 3 4 . \n" - ] - } - ], + "outputs": [], "source": [ "V('1 2 [3] [4] b')" ] @@ -2793,17 +1846,9 @@ }, { "cell_type": "code", - "execution_count": 121, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3 2 1 0\n" - ] - } - ], + "outputs": [], "source": [ "J('3 [0 >] [dup --] while')" ] @@ -2817,48 +1862,18 @@ }, { "cell_type": "code", - "execution_count": 122, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "x == dup i\n", - "\n", - "... [Q] x = ... [Q] dup i\n", - "... [Q] x = ... [Q] [Q] i\n", - "... [Q] x = ... [Q] Q\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "J('[x] help')" ] }, { "cell_type": "code", - "execution_count": 123, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " . 1 [2] [i 3] x\n", - " 1 . [2] [i 3] x\n", - " 1 [2] . [i 3] x\n", - "1 [2] [i 3] . x\n", - "1 [2] [i 3] . i 3\n", - " 1 [2] . i 3 3\n", - " 1 . 2 3 3\n", - " 1 2 . 3 3\n", - " 1 2 3 . 3\n", - " 1 2 3 3 . \n" - ] - } - ], + "outputs": [], "source": [ "V('1 [2] [i 3] x') # Kind of a pointless example." ] @@ -2873,68 +1888,36 @@ }, { "cell_type": "code", - "execution_count": 124, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "False\n" - ] - } - ], + "outputs": [], "source": [ "J('[] void')" ] }, { "cell_type": "code", - "execution_count": 125, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" - ] - } - ], + "outputs": [], "source": [ "J('[[]] void')" ] }, { "cell_type": "code", - "execution_count": 126, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" - ] - } - ], + "outputs": [], "source": [ "J('[[][[]]] void')" ] }, { "cell_type": "code", - "execution_count": 127, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "False\n" - ] - } - ], + "outputs": [], "source": [ "J('[[[]][[][]]] void')" ] @@ -2956,7 +1939,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.13" + "version": "2.7.12" } }, "nbformat": 4, diff --git a/docs/fun_with_scan.html b/docs/fun_with_scan.html index 44733f8..b21d010 100644 --- a/docs/fun_with_scan.html +++ b/docs/fun_with_scan.html @@ -11773,7 +11773,7 @@ div#notebook {
-
In [1]:
+
In [2]:
from notebook_preamble import D, DefinitionWrapper, J, V, define
@@ -11789,6 +11789,7 @@ div#notebook {
 

On "Two Exercises Found in a Book on Algorithmics"

Bird & Meertens

+

PDF paper available here

@@ -11806,7 +11807,7 @@ div#notebook {

The problem is to find some definition of scan as a reduction. In other words, we have to find some function f and an operator so that

-
⨂\x = f(a)⨂f(b)⨂...⨂f(z)
+
⨁\x = f(a)⨂f(b)⨂...⨂f(z)
@@ -11941,7 +11942,7 @@ scan == [size 1 <=] [pop []] [[[F] infra] dupdip first] [dip swons] genrec
-
In [2]:
+
In [3]:
J('[1 2 3] [size 1 <=] [pop []] [[[+] infra] dupdip first] [dip swons] genrec')
@@ -11981,7 +11982,7 @@ scan == [size 1 <=] [pop []] [[[F] infra] dupdip first] [dip swons] genrec
 
-
In [3]:
+
In [4]:
J('[1 2 3] [size 1 <=] [[]] [[[+] infra] dupdip first] [dip swons] genrec')
@@ -12021,7 +12022,7 @@ scan == [size 1 <=] [pop []] [[[F] infra] dupdip first] [dip swons] genrec
 
-
In [4]:
+
In [5]:
J('[1 2 3] [size 1 <=] [] [[[+] infra] dupdip first] [dip swons] genrec')
@@ -12076,7 +12077,7 @@ scan == [size 1 <=] [pop []] [[[F] infra] dupdip first] [dip swons] genrec
 
-
In [5]:
+
In [6]:
define('scan == [infra] cons [dupdip first] cons [size 1 <=] [] roll< [dip swons] genrec')
@@ -12089,7 +12090,7 @@ scan == [size 1 <=] [pop []] [[[F] infra] dupdip first] [dip swons] genrec
 
-
In [6]:
+
In [7]:
J('[1 2 3 4] [+] scan')
@@ -12120,7 +12121,7 @@ scan == [size 1 <=] [pop []] [[[F] infra] dupdip first] [dip swons] genrec
 
-
In [7]:
+
In [8]:
J('[1 2 3 4] [*] scan')
@@ -12151,7 +12152,7 @@ scan == [size 1 <=] [pop []] [[[F] infra] dupdip first] [dip swons] genrec
 
-
In [8]:
+
In [9]:
J('[1 2 3 4 5 6 7] [neg +] scan')
diff --git a/docs/fun_with_scan.md b/docs/fun_with_scan.md
index 5e0cf67..79d1408 100644
--- a/docs/fun_with_scan.md
+++ b/docs/fun_with_scan.md
@@ -8,6 +8,8 @@ from notebook_preamble import D, DefinitionWrapper, J, V, define
 
 Bird & Meertens
 
+[PDF paper available here](https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.694.2614)
+
 ## Define `scan` in terms of a reduction.
 
 > Problem I. The reduction operator `/` of APL takes some binary operator `⨁` on its left and a vector `x` of values on its right. The meaning of `⨁/x` for `x = [a b ... z]` is the value `a⨁b⨁...⨁z`.  For this to be well-defined in the absence of brackets, the operation `⨁` has to be associative.  Now there is another operator `\` of APL called `scan`.  Its effect is closely related to reduction in that we have:
@@ -16,7 +18,7 @@ Bird & Meertens
 
 > The problem is to find some definition of `scan` as a reduction.  In other words, we have to find some function `f` and an operator `⨂` so that
 
-    ⨂\x = f(a)⨂f(b)⨂...⨂f(z)
+    ⨁\x = f(a)⨂f(b)⨂...⨂f(z)
 
 ## Designing the Recursive Function
 Ignoring the exact requirements (finding `f` and `⨂`) can we implement `scan` as a hylomorphism in Joy?
diff --git a/docs/fun_with_scan.rst b/docs/fun_with_scan.rst
index ff54dc4..8c672eb 100644
--- a/docs/fun_with_scan.rst
+++ b/docs/fun_with_scan.rst
@@ -8,6 +8,9 @@ On "Two Exercises Found in a Book on Algorithmics"
 
 Bird & Meertens
 
+`PDF paper available
+here `__
+
 Define ``scan`` in terms of a reduction.
 ----------------------------------------
 
@@ -29,7 +32,7 @@ Define ``scan`` in terms of a reduction.
 
 ::
 
-    ⨂\x = f(a)⨂f(b)⨂...⨂f(z)
+    ⨁\x = f(a)⨂f(b)⨂...⨂f(z)
 
 Designing the Recursive Function
 --------------------------------
diff --git a/docs/sphinx_docs/_build/html/_modules/index.html b/docs/sphinx_docs/_build/html/_modules/index.html
index 836a9f4..5b46260 100644
--- a/docs/sphinx_docs/_build/html/_modules/index.html
+++ b/docs/sphinx_docs/_build/html/_modules/index.html
@@ -36,7 +36,6 @@
 
  • joy.library
  • joy.parser
  • joy.utils.generated_library
  • -
  • joy.utils.polytypes
  • joy.utils.pretty_print
  • joy.utils.stack
  • joy.utils.types
  • diff --git a/docs/sphinx_docs/_build/html/_modules/joy/joy.html b/docs/sphinx_docs/_build/html/_modules/joy/joy.html index bf0f436..a30fc24 100644 --- a/docs/sphinx_docs/_build/html/_modules/joy/joy.html +++ b/docs/sphinx_docs/_build/html/_modules/joy/joy.html @@ -57,10 +57,7 @@ ''' from __future__ import print_function -try: - input = raw_input -except NameError: - pass +from builtins import input from traceback import print_exc, format_exc from .parser import text_to_expression, ParseError, Symbol from .utils.stack import stack_to_string @@ -68,86 +65,89 @@
    [docs]def joy(stack, expression, dictionary, viewer=None): - '''Evaluate the Joy expression on the stack. - - The basic joy() function is quite straightforward. It iterates through a - sequence of terms which are either literals (strings, numbers, sequences) - or functions. Literals are put onto the stack and functions are - executed. + '''Evaluate a Joy expression on a stack. - :param stack stack: The stack. - :param stack expression: The expression to evaluate. - :param dict dictionary: A ``dict`` mapping names to Joy functions. - :param function viewer: Optional viewer function. - :rtype: (stack, (), dictionary) + This function iterates through a sequence of terms which are either + literals (strings, numbers, sequences of terms) or function symbols. + Literals are put onto the stack and functions are looked up in the + disctionary and executed. - ''' - while expression: + The viewer is a function that is called with the stack and expression + on every iteration, its return value is ignored. - if viewer: viewer(stack, expression) + :param stack stack: The stack. + :param stack expression: The expression to evaluate. + :param dict dictionary: A ``dict`` mapping names to Joy functions. + :param function viewer: Optional viewer function. + :rtype: (stack, (), dictionary) - term, expression = expression - if isinstance(term, Symbol): - term = dictionary[term] - stack, expression, dictionary = term(stack, expression, dictionary) - else: - stack = term, stack + ''' + while expression: - if viewer: viewer(stack, expression) - return stack, expression, dictionary
    + if viewer: viewer(stack, expression) + + term, expression = expression + if isinstance(term, Symbol): + term = dictionary[term] + stack, expression, dictionary = term(stack, expression, dictionary) + else: + stack = term, stack + + if viewer: viewer(stack, expression) + return stack, expression, dictionary
    [docs]def run(text, stack, dictionary, viewer=None): - ''' - Return the stack resulting from running the Joy code text on the stack. + ''' + Return the stack resulting from running the Joy code text on the stack. - :param str text: Joy code. - :param stack stack: The stack. - :param dict dictionary: A ``dict`` mapping names to Joy functions. - :param function viewer: Optional viewer function. - :rtype: (stack, (), dictionary) + :param str text: Joy code. + :param stack stack: The stack. + :param dict dictionary: A ``dict`` mapping names to Joy functions. + :param function viewer: Optional viewer function. + :rtype: (stack, (), dictionary) - ''' - expression = text_to_expression(text) - return joy(stack, expression, dictionary, viewer)
    + ''' + expression = text_to_expression(text) + return joy(stack, expression, dictionary, viewer)
    [docs]def repl(stack=(), dictionary=None): - ''' - Read-Evaluate-Print Loop + ''' + Read-Evaluate-Print Loop - Accept input and run it on the stack, loop. + Accept input and run it on the stack, loop. - :param stack stack: The stack. - :param dict dictionary: A ``dict`` mapping names to Joy functions. - :rtype: stack + :param stack stack: The stack. + :param dict dictionary: A ``dict`` mapping names to Joy functions. + :rtype: stack - ''' - if dictionary is None: - dictionary = {} - try: - while True: - print() - print(stack_to_string(stack), '<-top') - print() - try: - text = input('joy? ') - except (EOFError, KeyboardInterrupt): - break - viewer = TracePrinter() - try: - stack, _, dictionary = run(text, stack, dictionary, viewer.viewer) - except: - exc = format_exc() # Capture the exception. - viewer.print_() # Print the Joy trace. - print('-' * 73) - print(exc) # Print the original exception. - else: - viewer.print_() - except: - print_exc() - print() - return stack
    + ''' + if dictionary is None: + dictionary = {} + try: + while True: + print() + print(stack_to_string(stack), '<-top') + print() + try: + text = input('joy? ') + except (EOFError, KeyboardInterrupt): + break + viewer = TracePrinter() + try: + stack, _, dictionary = run(text, stack, dictionary, viewer.viewer) + except: + exc = format_exc() # Capture the exception. + viewer.print_() # Print the Joy trace. + print('-' * 73) + print(exc) # Print the original exception. + else: + viewer.print_() + except: + print_exc() + print() + return stack
    diff --git a/docs/sphinx_docs/_build/html/_modules/joy/library.html b/docs/sphinx_docs/_build/html/_modules/joy/library.html index dc60009..b9ac7d8 100644 --- a/docs/sphinx_docs/_build/html/_modules/joy/library.html +++ b/docs/sphinx_docs/_build/html/_modules/joy/library.html @@ -56,82 +56,204 @@ returns a dictionary of Joy functions suitable for use with the joy() function. ''' +from __future__ import print_function +from builtins import map, object, range, zip +from logging import getLogger + +_log = getLogger(__name__) +_log.info('Loading library.') + from inspect import getdoc from functools import wraps +from itertools import count from inspect import getmembers, isfunction import operator, math from .parser import text_to_expression, Symbol -from .utils.stack import list_to_stack, iter_stack, pick, concat -from .utils.brutal_hackery import rename_code_object +from .utils.stack import expression_to_string, list_to_stack, iter_stack, pick, concat +import sys +if sys.version_info.major < 3: + from .utils.brutal_hackery import rename_code_object +else: + rename_code_object = lambda _: lambda f: f from .utils import generated_library as genlib +from .utils.types import ( + compose, + ef, + stack_effect, + AnyJoyType, + AnyStarJoyType, + BooleanJoyType, + NumberJoyType, + NumberStarJoyType, + StackJoyType, + StackStarJoyType, + FloatJoyType, + IntJoyType, + SymbolJoyType, + CombinatorJoyType, + TextJoyType, + _functions, + FUNCTIONS, + infer, + infer_expression, + JoyTypeError, + combinator_effect, + poly_combinator_effect, + doc_from_stack_effect, + ) +_SYM_NUMS = lambda c=count(): next(c) +_COMB_NUMS = lambda c=count(): next(c) + + +_R = list(range(10)) +A = a0, a1, a2, a3, a4, a5, a6, a7, a8, a9 = list(map(AnyJoyType, _R)) +B = b0, b1, b2, b3, b4, b5, b6, b7, b8, b9 = list(map(BooleanJoyType, _R)) +N = n0, n1, n2, n3, n4, n5, n6, n7, n8, n9 = list(map(NumberJoyType, _R)) +S = s0, s1, s2, s3, s4, s5, s6, s7, s8, s9 = list(map(StackJoyType, _R)) +F = f0, f1, f2, f3, f4, f5, f6, f7, f8, f9 = list(map(FloatJoyType, _R)) +I = i0, i1, i2, i3, i4, i5, i6, i7, i8, i9 = list(map(IntJoyType, _R)) +T = t0, t1, t2, t3, t4, t5, t6, t7, t8, t9 = list(map(TextJoyType, _R)) + + +_R = list(range(1, 11)) +As = list(map(AnyStarJoyType, _R)) +Ns = list(map(NumberStarJoyType, _R)) +Ss = list(map(StackStarJoyType, _R)) + + +sec0 = stack_effect(t1)() +sec1 = stack_effect(s0, i1)(s1) +sec2 = stack_effect(s0, i1)(a1) +sec_binary_cmp = stack_effect(n1, n2)(b1) +sec_binary_ints = stack_effect(i1, i2)(i3) +sec_binary_logic = stack_effect(b1, b2)(b3) +sec_binary_math = stack_effect(n1, n2)(n3) +sec_unary_logic = stack_effect(a1)(b1) +sec_unary_math = stack_effect(n1)(n2) +sec_Ns_math = stack_effect((Ns[1], s1),)(n0) + _dictionary = {}
    [docs]def inscribe(function): - '''A decorator to inscribe functions into the default dictionary.''' - _dictionary[function.name] = function - return function
    + '''A decorator to inscribe functions into the default dictionary.''' + _dictionary[function.name] = function + return function
    [docs]def initialize(): - '''Return a dictionary of Joy functions for use with joy().''' - return _dictionary.copy()
    + '''Return a dictionary of Joy functions for use with joy().''' + return _dictionary.copy()
    ALIASES = ( - ('add', ['+']), - ('and', ['&']), - ('bool', ['truthy']), - ('mul', ['*']), - ('truediv', ['/']), - ('mod', ['%', 'rem', 'remainder', 'modulus']), - ('eq', ['=']), - ('ge', ['>=']), - ('getitem', ['pick', 'at']), - ('gt', ['>']), - ('le', ['<=']), - ('lshift', ['<<']), - ('lt', ['<']), - ('ne', ['<>', '!=']), - ('rshift', ['>>']), - ('sub', ['-']), - ('xor', ['^']), - ('succ', ['++']), - ('pred', ['--']), - ('rolldown', ['roll<']), - ('rollup', ['roll>']), - ('id', [u'•']), - ) + ('add', ['+']), + ('and', ['&']), + ('bool', ['truthy']), + ('mul', ['*']), + ('floordiv', ['/floor', '//']), + ('floor', ['round']), + ('truediv', ['/']), + ('mod', ['%', 'rem', 'remainder', 'modulus']), + ('eq', ['=']), + ('ge', ['>=']), + ('getitem', ['pick', 'at']), + ('gt', ['>']), + ('le', ['<=']), + ('lshift', ['<<']), + ('lt', ['<']), + ('ne', ['<>', '!=']), + ('rshift', ['>>']), + ('sub', ['-']), + ('xor', ['^']), + ('succ', ['++']), + ('pred', ['--']), + ('rolldown', ['roll<']), + ('rollup', ['roll>']), + ('eh', ['?']), + ('id', [u'•']), + )
    [docs]def add_aliases(D, A): - ''' - Given a dict and a iterable of (name, [alias, ...]) pairs, create - additional entries in the dict mapping each alias to the named function - if it's in the dict. Aliases for functions not in the dict are ignored. - ''' - for name, aliases in A: - try: - F = D[name] - except KeyError: - continue - for alias in aliases: - D[alias] = F
    + ''' + Given a dict and a iterable of (name, [alias, ...]) pairs, create + additional entries in the dict mapping each alias to the named function + if it's in the dict. Aliases for functions not in the dict are ignored. + ''' + for name, aliases in A: + try: + F = D[name] + except KeyError: + continue + for alias in aliases: + D[alias] = F
    + + +
    [docs]def yin_functions(): + ''' + Return a dict of named stack effects. + + "Yin" functions are those that only rearrange items in stacks and + can be defined completely by their stack effects. This means they + can be auto-compiled. + ''' + # pylint: disable=unused-variable + cons = ef(a1, s0)((a1, s0)) + ccons = compose(cons, cons) + dup = ef(a1)(a1, a1) + dupd = ef(a2, a1)(a2, a2, a1) + dupdd = ef(a3, a2, a1)(a3, a3, a2, a1) + first = ef((a1, s1),)(a1,) + over = ef(a2, a1)(a2, a1, a2) + pop = ef(a1)() + popd = ef(a2, a1,)(a1) + popdd = ef(a3, a2, a1,)(a2, a1,) + popop = ef(a2, a1,)() + popopd = ef(a3, a2, a1,)(a1) + popopdd = ef(a4, a3, a2, a1,)(a2, a1) + rest = ef((a1, s0),)(s0,) + rolldown = ef(a1, a2, a3)(a2, a3, a1) + rollup = ef(a1, a2, a3)(a3, a1, a2) + rrest = compose(rest, rest) + second = compose(rest, first) + stack = s0, (s0, s0) + swaack = (s1, s0), (s0, s1) + swap = ef(a1, a2)(a2, a1) + swons = compose(swap, cons) + third = compose(rest, second) + tuck = ef(a2, a1)(a1, a2, a1) + uncons = ef((a1, s0),)(a1, s0) + unswons = compose(uncons, swap) + stuncons = compose(stack, uncons) + stununcons = compose(stack, uncons, uncons) + unit = ef(a1)((a1, ())) + + first_two = compose(uncons, uncons, pop) + fourth = compose(rest, third) + + _Tree_add_Ee = compose(pop, swap, rolldown, rrest, ccons) + _Tree_get_E = compose(popop, second) + _Tree_delete_clear_stuff = compose(rollup, popop, rest) + _Tree_delete_R0 = compose(over, first, swap, dup) + + return locals()
    definitions = ('''\ +ii == [dip] dupdip i of == swap at product == 1 swap [*] step flatten == [] swap [concat] step quoted == [unit] dip unquoted == [i] dip enstacken == stack [clear] dip -disenstacken == ? [uncons ?] loop pop ? == dup truthy +disenstacken == ? [uncons ?] loop pop dinfrirst == dip infra first nullary == [stack] dinfrirst unary == nullary popd @@ -160,7 +282,8 @@ make_generator == [codireco] ccons ifte == [nullary not] dipd branch ''' -# +# +# # ifte == [nullary] dipd swap branch # genrec == [[genrec] cons cons cons cons] nullary swons concat ifte @@ -203,102 +326,110 @@
    [docs]def FunctionWrapper(f): - '''Set name attribute.''' - if not f.__doc__: - raise ValueError('Function %s must have doc string.' % f.__name__) - f.name = f.__name__.rstrip('_') # Don't shadow builtins. - return f
    + '''Set name attribute.''' + if not f.__doc__: + raise ValueError('Function %s must have doc string.' % f.__name__) + f.name = f.__name__.rstrip('_') # Don't shadow builtins. + return f
    [docs]def SimpleFunctionWrapper(f): - ''' - Wrap functions that take and return just a stack. - ''' - @FunctionWrapper - @wraps(f) - @rename_code_object(f.__name__) - def inner(stack, expression, dictionary): - return f(stack), expression, dictionary - return inner
    + ''' + Wrap functions that take and return just a stack. + ''' + @FunctionWrapper + @wraps(f) + @rename_code_object(f.__name__) + def inner(stack, expression, dictionary): + return f(stack), expression, dictionary + return inner
    [docs]def BinaryBuiltinWrapper(f): - ''' - Wrap functions that take two arguments and return a single result. - ''' - @FunctionWrapper - @wraps(f) - @rename_code_object(f.__name__) - def inner(stack, expression, dictionary): - (a, (b, stack)) = stack - result = f(b, a) - return (result, stack), expression, dictionary - return inner
    + ''' + Wrap functions that take two arguments and return a single result. + ''' + @FunctionWrapper + @wraps(f) + @rename_code_object(f.__name__) + def inner(stack, expression, dictionary): + (a, (b, stack)) = stack + result = f(b, a) + return (result, stack), expression, dictionary + return inner
    [docs]def UnaryBuiltinWrapper(f): - ''' - Wrap functions that take one argument and return a single result. - ''' - @FunctionWrapper - @wraps(f) - @rename_code_object(f.__name__) - def inner(stack, expression, dictionary): - (a, stack) = stack - result = f(a) - return (result, stack), expression, dictionary - return inner
    + ''' + Wrap functions that take one argument and return a single result. + ''' + @FunctionWrapper + @wraps(f) + @rename_code_object(f.__name__) + def inner(stack, expression, dictionary): + (a, stack) = stack + result = f(a) + return (result, stack), expression, dictionary + return inner
    [docs]class DefinitionWrapper(object): - ''' - Provide implementation of defined functions, and some helper methods. - ''' + ''' + Provide implementation of defined functions, and some helper methods. + ''' - def __init__(self, name, body_text, doc=None): - self.name = self.__name__ = name - self.body = text_to_expression(body_text) - self._body = tuple(iter_stack(self.body)) - self.__doc__ = doc or body_text - self._compiled = None + def __init__(self, name, body_text, doc=None): + self.name = self.__name__ = name + self.body = text_to_expression(body_text) + self._body = tuple(iter_stack(self.body)) + self.__doc__ = doc or body_text + self._compiled = None - def __call__(self, stack, expression, dictionary): - if self._compiled: - return self._compiled(stack, expression, dictionary) - expression = list_to_stack(self._body, expression) - return stack, expression, dictionary + def __call__(self, stack, expression, dictionary): + if self._compiled: + return self._compiled(stack, expression, dictionary) # pylint: disable=E1102 + expression = list_to_stack(self._body, expression) + return stack, expression, dictionary -
    [docs] @classmethod - def parse_definition(class_, defi): - ''' - Given some text describing a Joy function definition parse it and - return a DefinitionWrapper. - ''' - name, proper, body_text = (n.strip() for n in defi.partition('==')) - if not proper: - raise ValueError('Definition %r failed' % (defi,)) - return class_(name, body_text)
    +
    [docs] @classmethod + def parse_definition(class_, defi): + ''' + Given some text describing a Joy function definition parse it and + return a DefinitionWrapper. + ''' + name, proper, body_text = (n.strip() for n in defi.partition('==')) + if not proper: + raise ValueError('Definition %r failed' % (defi,)) + return class_(name, body_text)
    -
    [docs] @classmethod - def add_definitions(class_, defs, dictionary): - ''' - Scan multi-line string defs for definitions and add them to the - dictionary. - ''' - for definition in _text_to_defs(defs): - class_.add_def(definition, dictionary)
    +
    [docs] @classmethod + def add_definitions(class_, defs, dictionary): + ''' + Scan multi-line string defs for definitions and add them to the + dictionary. + ''' + for definition in _text_to_defs(defs): + class_.add_def(definition, dictionary)
    -
    [docs] @classmethod - def add_def(class_, definition, dictionary): - ''' - Add the definition to the dictionary. - ''' - F = class_.parse_definition(definition) - dictionary[F.name] = F
    +
    [docs] @classmethod + def add_def(class_, definition, dictionary, fail_fails=False): + ''' + Add the definition to the dictionary. + ''' + F = class_.parse_definition(definition) + _log.info('Adding definition %s := %s', F.name, expression_to_string(F.body)) + dictionary[F.name] = F
    + + @classmethod + def load_definitions(class_, filename, dictionary): + with open(filename) as f: + lines = [line for line in f if '==' in line] + for line in lines: + class_.add_def(line, dictionary)
    def _text_to_defs(text): - return (line.strip() for line in text.splitlines() if '==' in line) + return (line.strip() for line in text.splitlines() if '==' in line) # @@ -306,331 +437,364 @@ # -# Load the auto-generated primitives into the dictionary. -for name, primitive in getmembers(genlib, isfunction): - inscribe(SimpleFunctionWrapper(primitive)) +
    [docs]@inscribe +@sec0 +@FunctionWrapper +def inscribe_(stack, expression, dictionary): + ''' + Create a new Joy function definition in the Joy dictionary. A + definition is given as a string with a name followed by a double + equal sign then one or more Joy functions, the body. for example: + + sqr == dup mul + + If you want the definition to persist over restarts, enter it into + the definitions.txt resource. + ''' + definition, stack = stack + DefinitionWrapper.add_def(definition, dictionary, fail_fails=True) + return stack, expression, dictionary
    [docs]@inscribe @SimpleFunctionWrapper def parse(stack): - '''Parse the string on the stack to a Joy expression.''' - text, stack = stack - expression = text_to_expression(text) - return expression, stack
    + '''Parse the string on the stack to a Joy expression.''' + text, stack = stack + expression = text_to_expression(text) + return expression, stack
    + + +
    [docs]@inscribe +@SimpleFunctionWrapper +def infer_(stack): + '''Attempt to infer the stack effect of a Joy expression.''' + E, stack = stack + effects = infer_expression(E) + e = list_to_stack([(fi, (fo, ())) for fi, fo in effects]) + return e, stack
    [docs]@inscribe +@sec2 @SimpleFunctionWrapper def getitem(stack): - ''' - :: + ''' + :: - getitem == drop first + getitem == drop first - Expects an integer and a quote on the stack and returns the item at the - nth position in the quote counting from 0. - :: + Expects an integer and a quote on the stack and returns the item at the + nth position in the quote counting from 0. + :: - [a b c d] 0 getitem - ------------------------- - a + [a b c d] 0 getitem + ------------------------- + a - ''' - n, (Q, stack) = stack - return pick(Q, n), stack
    + ''' + n, (Q, stack) = stack + return pick(Q, n), stack
    [docs]@inscribe +@sec1 @SimpleFunctionWrapper def drop(stack): - ''' - :: + ''' + :: - drop == [rest] times + drop == [rest] times - Expects an integer and a quote on the stack and returns the quote with - n items removed off the top. - :: + Expects an integer and a quote on the stack and returns the quote with + n items removed off the top. + :: - [a b c d] 2 drop - ---------------------- - [c d] + [a b c d] 2 drop + ---------------------- + [c d] - ''' - n, (Q, stack) = stack - while n > 0: - try: - _, Q = Q - except ValueError: - raise IndexError - n -= 1 - return Q, stack
    + ''' + n, (Q, stack) = stack + while n > 0: + try: + _, Q = Q + except ValueError: + raise IndexError + n -= 1 + return Q, stack
    [docs]@inscribe +@sec1 @SimpleFunctionWrapper def take(stack): - ''' - Expects an integer and a quote on the stack and returns the quote with - just the top n items in reverse order (because that's easier and you can - use reverse if needed.) - :: + ''' + Expects an integer and a quote on the stack and returns the quote with + just the top n items in reverse order (because that's easier and you can + use reverse if needed.) + :: - [a b c d] 2 take - ---------------------- - [b a] + [a b c d] 2 take + ---------------------- + [b a] - ''' - n, (Q, stack) = stack - x = () - while n > 0: - try: - item, Q = Q - except ValueError: - raise IndexError - x = item, x - n -= 1 - return x, stack
    + ''' + n, (Q, stack) = stack + x = () + while n > 0: + try: + item, Q = Q + except ValueError: + raise IndexError + x = item, x + n -= 1 + return x, stack
    [docs]@inscribe @SimpleFunctionWrapper def choice(stack): - ''' - Use a Boolean value to select one of two items. - :: + ''' + Use a Boolean value to select one of two items. + :: - A B False choice - ---------------------- - A + A B False choice + ---------------------- + A - A B True choice - --------------------- - B + A B True choice + --------------------- + B - Currently Python semantics are used to evaluate the "truthiness" of the - Boolean value (so empty string, zero, etc. are counted as false, etc.) - ''' - (if_, (then, (else_, stack))) = stack - return then if if_ else else_, stack
    + Currently Python semantics are used to evaluate the "truthiness" of the + Boolean value (so empty string, zero, etc. are counted as false, etc.) + ''' + (if_, (then, (else_, stack))) = stack + return then if if_ else else_, stack
    [docs]@inscribe @SimpleFunctionWrapper def select(stack): - ''' - Use a Boolean value to select one of two items from a sequence. - :: + ''' + Use a Boolean value to select one of two items from a sequence. + :: - [A B] False select - ------------------------ - A + [A B] False select + ------------------------ + A - [A B] True select - ----------------------- - B + [A B] True select + ----------------------- + B - The sequence can contain more than two items but not fewer. - Currently Python semantics are used to evaluate the "truthiness" of the - Boolean value (so empty string, zero, etc. are counted as false, etc.) - ''' - (flag, (choices, stack)) = stack - (else_, (then, _)) = choices - return then if flag else else_, stack
    + The sequence can contain more than two items but not fewer. + Currently Python semantics are used to evaluate the "truthiness" of the + Boolean value (so empty string, zero, etc. are counted as false, etc.) + ''' + (flag, (choices, stack)) = stack + (else_, (then, _)) = choices + return then if flag else else_, stack
    [docs]@inscribe +@sec_Ns_math @SimpleFunctionWrapper def max_(S): - '''Given a list find the maximum.''' - tos, stack = S - return max(iter_stack(tos)), stack
    + '''Given a list find the maximum.''' + tos, stack = S + return max(iter_stack(tos)), stack
    [docs]@inscribe +@sec_Ns_math @SimpleFunctionWrapper def min_(S): - '''Given a list find the minimum.''' - tos, stack = S - return min(iter_stack(tos)), stack
    + '''Given a list find the minimum.''' + tos, stack = S + return min(iter_stack(tos)), stack
    [docs]@inscribe +@sec_Ns_math @SimpleFunctionWrapper def sum_(S): - '''Given a quoted sequence of numbers return the sum. + '''Given a quoted sequence of numbers return the sum. - sum == 0 swap [+] step - ''' - tos, stack = S - return sum(iter_stack(tos)), stack
    + sum == 0 swap [+] step + ''' + tos, stack = S + return sum(iter_stack(tos)), stack
    [docs]@inscribe @SimpleFunctionWrapper def remove(S): - ''' - Expects an item on the stack and a quote under it and removes that item - from the the quote. The item is only removed once. - :: + ''' + Expects an item on the stack and a quote under it and removes that item + from the the quote. The item is only removed once. + :: - [1 2 3 1] 1 remove - ------------------------ - [2 3 1] + [1 2 3 1] 1 remove + ------------------------ + [2 3 1] - ''' - (tos, (second, stack)) = S - l = list(iter_stack(second)) - l.remove(tos) - return list_to_stack(l), stack
    + ''' + (tos, (second, stack)) = S + l = list(iter_stack(second)) + l.remove(tos) + return list_to_stack(l), stack
    [docs]@inscribe @SimpleFunctionWrapper def unique(S): - '''Given a list remove duplicate items.''' - tos, stack = S - I = list(iter_stack(tos)) - list_to_stack(sorted(set(I), key=I.index)) - return list_to_stack(sorted(set(I), key=I.index)), stack
    + '''Given a list remove duplicate items.''' + tos, stack = S + I = list(iter_stack(tos)) + return list_to_stack(sorted(set(I), key=I.index)), stack
    [docs]@inscribe @SimpleFunctionWrapper def sort_(S): - '''Given a list return it sorted.''' - tos, stack = S - return list_to_stack(sorted(iter_stack(tos))), stack
    + '''Given a list return it sorted.''' + tos, stack = S + return list_to_stack(sorted(iter_stack(tos))), stack
    +_functions['clear'] = s0, s1
    [docs]@inscribe @SimpleFunctionWrapper def clear(stack): - '''Clear everything from the stack. - :: + '''Clear everything from the stack. + :: - clear == stack [pop stack] loop + clear == stack [pop stack] loop - ... clear - --------------- + ... clear + --------------- - ''' - return ()
    + ''' + return ()
    [docs]@inscribe @SimpleFunctionWrapper def unstack(stack): - ''' - The unstack operator expects a list on top of the stack and makes that - the stack discarding the rest of the stack. - ''' - return stack[0]
    + ''' + The unstack operator expects a list on top of the stack and makes that + the stack discarding the rest of the stack. + ''' + return stack[0]
    [docs]@inscribe @SimpleFunctionWrapper def reverse(S): - '''Reverse the list on the top of the stack. - :: + '''Reverse the list on the top of the stack. + :: - reverse == [] swap shunt - ''' - (tos, stack) = S - res = () - for term in iter_stack(tos): - res = term, res - return res, stack
    + reverse == [] swap shunt + ''' + (tos, stack) = S + res = () + for term in iter_stack(tos): + res = term, res + return res, stack
    [docs]@inscribe +@combinator_effect(_COMB_NUMS(), s7, s6) @SimpleFunctionWrapper def concat_(S): - '''Concatinate the two lists on the top of the stack. - :: + '''Concatinate the two lists on the top of the stack. + :: - [a b c] [d e f] concat - ---------------------------- - [a b c d e f] + [a b c] [d e f] concat + ---------------------------- + [a b c d e f] ''' - (tos, (second, stack)) = S - return concat(second, tos), stack
    + (tos, (second, stack)) = S + return concat(second, tos), stack
    [docs]@inscribe @SimpleFunctionWrapper def shunt(stack): - '''Like concat but reverses the top list into the second. - :: + '''Like concat but reverses the top list into the second. + :: - shunt == [swons] step == reverse swap concat + shunt == [swons] step == reverse swap concat - [a b c] [d e f] shunt - --------------------------- - [f e d a b c] + [a b c] [d e f] shunt + --------------------------- + [f e d a b c] - ''' - (tos, (second, stack)) = stack - while tos: - term, tos = tos - second = term, second - return second, stack
    + ''' + (tos, (second, stack)) = stack + while tos: + term, tos = tos + second = term, second + return second, stack
    [docs]@inscribe @SimpleFunctionWrapper def zip_(S): - ''' - Replace the two lists on the top of the stack with a list of the pairs - from each list. The smallest list sets the length of the result list. - ''' - (tos, (second, stack)) = S - accumulator = [ - (a, (b, ())) - for a, b in zip(iter_stack(tos), iter_stack(second)) - ] - return list_to_stack(accumulator), stack
    + ''' + Replace the two lists on the top of the stack with a list of the pairs + from each list. The smallest list sets the length of the result list. + ''' + (tos, (second, stack)) = S + accumulator = [ + (a, (b, ())) + for a, b in zip(iter_stack(tos), iter_stack(second)) + ] + return list_to_stack(accumulator), stack
    [docs]@inscribe +@sec_unary_math @SimpleFunctionWrapper def succ(S): - '''Increment TOS.''' - (tos, stack) = S - return tos + 1, stack
    + '''Increment TOS.''' + (tos, stack) = S + return tos + 1, stack
    [docs]@inscribe +@sec_unary_math @SimpleFunctionWrapper def pred(S): - '''Decrement TOS.''' - (tos, stack) = S - return tos - 1, stack
    + '''Decrement TOS.''' + (tos, stack) = S + return tos - 1, stack
    [docs]@inscribe @SimpleFunctionWrapper def pm(stack): - ''' - Plus or minus - :: + ''' + Plus or minus + :: - a b pm - ------------- - a+b a-b + a b pm + ------------- + a+b a-b - ''' - a, (b, stack) = stack - p, m, = b + a, b - a - return m, (p, stack)
    + ''' + a, (b, stack) = stack + p, m, = b + a, b - a + return m, (p, stack)
    [docs]def floor(n): - return int(math.floor(n))
    + return int(math.floor(n))
    floor.__doc__ = math.floor.__doc__ @@ -638,27 +802,27 @@
    [docs]@inscribe @SimpleFunctionWrapper def divmod_(S): - ''' - divmod(x, y) -> (quotient, remainder) + ''' + divmod(x, y) -> (quotient, remainder) - Return the tuple (x//y, x%y). Invariant: div*y + mod == x. - ''' - a, (b, stack) = S - d, m = divmod(a, b) - return d, (m, stack)
    + Return the tuple (x//y, x%y). Invariant: div*y + mod == x. + ''' + a, (b, stack) = S + d, m = divmod(a, b) + return d, (m, stack)
    [docs]def sqrt(a): - ''' - Return the square root of the number a. - Negative numbers return complex roots. - ''' - try: - r = math.sqrt(a) - except ValueError: - assert a < 0, repr(a) - r = math.sqrt(-a) * 1j - return r
    + ''' + Return the square root of the number a. + Negative numbers return complex roots. + ''' + try: + r = math.sqrt(a) + except ValueError: + assert a < 0, repr(a) + r = math.sqrt(-a) * 1j + return r #def execute(S): @@ -671,20 +835,20 @@
    [docs]@inscribe @SimpleFunctionWrapper def id_(stack): - '''The identity function.''' - return stack
    + '''The identity function.''' + return stack
    [docs]@inscribe @SimpleFunctionWrapper def void(stack): - '''True if the form on TOS is void otherwise False.''' - form, stack = stack - return _void(form), stack
    + '''True if the form on TOS is void otherwise False.''' + form, stack = stack + return _void(form), stack def _void(form): - return any(not _void(i) for i in iter_stack(form)) + return any(not _void(i) for i in iter_stack(form)) @@ -696,42 +860,42 @@
    [docs]@inscribe @FunctionWrapper def words(stack, expression, dictionary): - '''Print all the words in alphabetical order.''' - print(' '.join(sorted(dictionary))) - return stack, expression, dictionary
    + '''Print all the words in alphabetical order.''' + print(' '.join(sorted(dictionary))) + return stack, expression, dictionary
    [docs]@inscribe @FunctionWrapper def sharing(stack, expression, dictionary): - '''Print redistribution information.''' - print("You may convey verbatim copies of the Program's source code as" - ' you receive it, in any medium, provided that you conspicuously' - ' and appropriately publish on each copy an appropriate copyright' - ' notice; keep intact all notices stating that this License and' - ' any non-permissive terms added in accord with section 7 apply' - ' to the code; keep intact all notices of the absence of any' - ' warranty; and give all recipients a copy of this License along' - ' with the Program.' - ' You should have received a copy of the GNU General Public License' - ' along with Thun. If not see <http://www.gnu.org/licenses/>.') - return stack, expression, dictionary
    + '''Print redistribution information.''' + print("You may convey verbatim copies of the Program's source code as" + ' you receive it, in any medium, provided that you conspicuously' + ' and appropriately publish on each copy an appropriate copyright' + ' notice; keep intact all notices stating that this License and' + ' any non-permissive terms added in accord with section 7 apply' + ' to the code; keep intact all notices of the absence of any' + ' warranty; and give all recipients a copy of this License along' + ' with the Program.' + ' You should have received a copy of the GNU General Public License' + ' along with Thun. If not see <http://www.gnu.org/licenses/>.') + return stack, expression, dictionary
    [docs]@inscribe @FunctionWrapper def warranty(stack, expression, dictionary): - '''Print warranty information.''' - print('THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY' - ' APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE' - ' COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM' - ' "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR' - ' IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES' - ' OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE' - ' ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS' - ' WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE' - ' COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.') - return stack, expression, dictionary
    + '''Print warranty information.''' + print('THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY' + ' APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE' + ' COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM' + ' "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR' + ' IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES' + ' OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE' + ' ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS' + ' WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE' + ' COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.') + return stack, expression, dictionary # def simple_manual(stack): @@ -756,11 +920,11 @@
    [docs]@inscribe @FunctionWrapper def help_(S, expression, dictionary): - '''Accepts a quoted symbol on the top of the stack and prints its docs.''' - ((symbol, _), stack) = S - word = dictionary[symbol] - print(getdoc(word)) - return stack, expression, dictionary
    + '''Accepts a quoted symbol on the top of the stack and prints its docs.''' + ((symbol, _), stack) = S + word = dictionary[symbol] + print(getdoc(word)) + return stack, expression, dictionary # @@ -779,181 +943,188 @@ S_i = Symbol('i') S_ifte = Symbol('ifte') S_infra = Symbol('infra') +S_pop = Symbol('pop') S_step = Symbol('step') S_times = Symbol('times') S_swaack = Symbol('swaack') -S_truthy = Symbol('truthy')
    [docs]@inscribe +@combinator_effect(_COMB_NUMS(), s1) @FunctionWrapper def i(stack, expression, dictionary): - ''' - The i combinator expects a quoted program on the stack and unpacks it - onto the pending expression for evaluation. - :: + ''' + The i combinator expects a quoted program on the stack and unpacks it + onto the pending expression for evaluation. + :: - [Q] i - ----------- - Q + [Q] i + ----------- + Q - ''' - quote, stack = stack - return stack, concat(quote, expression), dictionary
    + ''' + quote, stack = stack + return stack, concat(quote, expression), dictionary
    [docs]@inscribe +@combinator_effect(_COMB_NUMS(), s1) @FunctionWrapper def x(stack, expression, dictionary): - ''' - :: + ''' + :: - x == dup i + x == dup i - ... [Q] x = ... [Q] dup i - ... [Q] x = ... [Q] [Q] i - ... [Q] x = ... [Q] Q + ... [Q] x = ... [Q] dup i + ... [Q] x = ... [Q] [Q] i + ... [Q] x = ... [Q] Q - ''' - quote, _ = stack - return stack, concat(quote, expression), dictionary
    + ''' + quote, _ = stack + return stack, concat(quote, expression), dictionary
    [docs]@inscribe +@combinator_effect(_COMB_NUMS(), s7, s6) @FunctionWrapper def b(stack, expression, dictionary): - ''' - :: + ''' + :: - b == [i] dip i + b == [i] dip i - ... [P] [Q] b == ... [P] i [Q] i - ... [P] [Q] b == ... P Q + ... [P] [Q] b == ... [P] i [Q] i + ... [P] [Q] b == ... P Q - ''' - q, (p, (stack)) = stack - return stack, concat(p, concat(q, expression)), dictionary
    + ''' + q, (p, (stack)) = stack + return stack, concat(p, concat(q, expression)), dictionary
    [docs]@inscribe +@combinator_effect(_COMB_NUMS(), a1, s1) @FunctionWrapper def dupdip(stack, expression, dictionary): - ''' - :: + ''' + :: - [F] dupdip == dup [F] dip + [F] dupdip == dup [F] dip - ... a [F] dupdip - ... a dup [F] dip - ... a a [F] dip - ... a F a + ... a [F] dupdip + ... a dup [F] dip + ... a a [F] dip + ... a F a - ''' - F, stack = stack - a = stack[0] - return stack, concat(F, (a, expression)), dictionary
    + ''' + F, stack = stack + a = stack[0] + return stack, concat(F, (a, expression)), dictionary
    [docs]@inscribe +@combinator_effect(_COMB_NUMS(), s7, s6) @FunctionWrapper def infra(stack, expression, dictionary): - ''' - Accept a quoted program and a list on the stack and run the program - with the list as its stack. - :: + ''' + Accept a quoted program and a list on the stack and run the program + with the list as its stack. Does not affect the rest of the stack. + :: - ... [a b c] [Q] . infra - ----------------------------- - c b a . Q [...] swaack + ... [a b c] [Q] . infra + ----------------------------- + c b a . Q [...] swaack - ''' - (quote, (aggregate, stack)) = stack - return aggregate, concat(quote, (stack, (S_swaack, expression))), dictionary
    + ''' + (quote, (aggregate, stack)) = stack + return aggregate, concat(quote, (stack, (S_swaack, expression))), dictionary
    [docs]@inscribe +#@combinator_effect(_COMB_NUMS(), s7, s6, s5, s4) @FunctionWrapper def genrec(stack, expression, dictionary): - ''' - General Recursion Combinator. - :: + ''' + General Recursion Combinator. + :: - [if] [then] [rec1] [rec2] genrec - --------------------------------------------------------------------- - [if] [then] [rec1 [[if] [then] [rec1] [rec2] genrec] rec2] ifte + [if] [then] [rec1] [rec2] genrec + --------------------------------------------------------------------- + [if] [then] [rec1 [[if] [then] [rec1] [rec2] genrec] rec2] ifte - From "Recursion Theory and Joy" (j05cmp.html) by Manfred von Thun: - "The genrec combinator takes four program parameters in addition to - whatever data parameters it needs. Fourth from the top is an if-part, - followed by a then-part. If the if-part yields true, then the then-part - is executed and the combinator terminates. The other two parameters are - the rec1-part and the rec2-part. If the if-part yields false, the - rec1-part is executed. Following that the four program parameters and - the combinator are again pushed onto the stack bundled up in a quoted - form. Then the rec2-part is executed, where it will find the bundled - form. Typically it will then execute the bundled form, either with i or - with app2, or some other combinator." + From "Recursion Theory and Joy" (j05cmp.html) by Manfred von Thun: + "The genrec combinator takes four program parameters in addition to + whatever data parameters it needs. Fourth from the top is an if-part, + followed by a then-part. If the if-part yields true, then the then-part + is executed and the combinator terminates. The other two parameters are + the rec1-part and the rec2-part. If the if-part yields false, the + rec1-part is executed. Following that the four program parameters and + the combinator are again pushed onto the stack bundled up in a quoted + form. Then the rec2-part is executed, where it will find the bundled + form. Typically it will then execute the bundled form, either with i or + with app2, or some other combinator." - The way to design one of these is to fix your base case [then] and the - test [if], and then treat rec1 and rec2 as an else-part "sandwiching" - a quotation of the whole function. + The way to design one of these is to fix your base case [then] and the + test [if], and then treat rec1 and rec2 as an else-part "sandwiching" + a quotation of the whole function. - For example, given a (general recursive) function 'F': - :: + For example, given a (general recursive) function 'F': + :: - F == [I] [T] [R1] [R2] genrec + F == [I] [T] [R1] [R2] genrec - If the [I] if-part fails you must derive R1 and R2 from: - :: + If the [I] if-part fails you must derive R1 and R2 from: + :: - ... R1 [F] R2 + ... R1 [F] R2 - Just set the stack arguments in front, and figure out what R1 and R2 - have to do to apply the quoted [F] in the proper way. In effect, the - genrec combinator turns into an ifte combinator with a quoted copy of - the original definition in the else-part: - :: + Just set the stack arguments in front, and figure out what R1 and R2 + have to do to apply the quoted [F] in the proper way. In effect, the + genrec combinator turns into an ifte combinator with a quoted copy of + the original definition in the else-part: + :: - F == [I] [T] [R1] [R2] genrec - == [I] [T] [R1 [F] R2] ifte + F == [I] [T] [R1] [R2] genrec + == [I] [T] [R1 [F] R2] ifte - Primitive recursive functions are those where R2 == i. - :: + Primitive recursive functions are those where R2 == i. + :: - P == [I] [T] [R] primrec - == [I] [T] [R [P] i] ifte - == [I] [T] [R P] ifte + P == [I] [T] [R] primrec + == [I] [T] [R [P] i] ifte + == [I] [T] [R P] ifte - ''' - (rec2, (rec1, stack)) = stack - (then, (if_, _)) = stack - F = (if_, (then, (rec1, (rec2, (S_genrec, ()))))) - else_ = concat(rec1, (F, rec2)) - return (else_, stack), (S_ifte, expression), dictionary
    + ''' + (rec2, (rec1, stack)) = stack + (then, (if_, _)) = stack + F = (if_, (then, (rec1, (rec2, (S_genrec, ()))))) + else_ = concat(rec1, (F, rec2)) + return (else_, stack), (S_ifte, expression), dictionary
    [docs]@inscribe +@combinator_effect(_COMB_NUMS(), s7, s6) @FunctionWrapper def map_(S, expression, dictionary): - ''' - Run the quoted program on TOS on the items in the list under it, push a - new list with the results (in place of the program and original list. - ''' + ''' + Run the quoted program on TOS on the items in the list under it, push a + new list with the results in place of the program and original list. + ''' # (quote, (aggregate, stack)) = S # results = list_to_stack([ # joy((term, stack), quote, dictionary)[0][0] # for term in iter_stack(aggregate) # ]) # return (results, stack), expression, dictionary - (quote, (aggregate, stack)) = S - if not aggregate: - return (aggregate, stack), expression, dictionary - batch = () - for term in iter_stack(aggregate): - s = term, stack - batch = (s, (quote, (S_infra, (S_first, batch)))) - stack = (batch, ((), stack)) - return stack, (S_infra, expression), dictionary
    + (quote, (aggregate, stack)) = S + if not aggregate: + return (aggregate, stack), expression, dictionary + batch = () + for term in iter_stack(aggregate): + s = term, stack + batch = (s, (quote, (S_infra, (S_first, batch)))) + stack = (batch, ((), stack)) + return stack, (S_infra, expression), dictionary #def cleave(S, expression, dictionary): @@ -970,29 +1141,45 @@ # return (q, (p, stack)), expression, dictionary +def branch_true(stack, expression, dictionary): + # pylint: disable=unused-variable + (then, (else_, (flag, stack))) = stack + return stack, concat(then, expression), dictionary + + +def branch_false(stack, expression, dictionary): + # pylint: disable=unused-variable + (then, (else_, (flag, stack))) = stack + return stack, concat(else_, expression), dictionary + +
    [docs]@inscribe +@poly_combinator_effect(_COMB_NUMS(), [branch_true, branch_false], b1, s7, s6) @FunctionWrapper def branch(stack, expression, dictionary): - ''' - Use a Boolean value to select one of two quoted programs to run. + ''' + Use a Boolean value to select one of two quoted programs to run. - :: + :: - branch == roll< choice i + branch == roll< choice i - :: + :: - False [F] [T] branch - -------------------------- - F + False [F] [T] branch + -------------------------- + F - True [F] [T] branch - ------------------------- - T + True [F] [T] branch + ------------------------- + T - ''' - (then, (else_, (flag, stack))) = stack - return stack, concat(then if flag else else_, expression), dictionary
    + ''' + (then, (else_, (flag, stack))) = stack + return stack, concat(then if flag else else_, expression), dictionary + + +#FUNCTIONS['branch'] = CombinatorJoyType('branch', [branch_true, branch_false], 100) ##@inscribe @@ -1026,223 +1213,231 @@
    [docs]@inscribe @FunctionWrapper def cond(stack, expression, dictionary): - ''' - This combinator works like a case statement. It expects a single quote - on the stack that must contain zero or more condition quotes and a - default quote. Each condition clause should contain a quoted predicate - followed by the function expression to run if that predicate returns - true. If no predicates return true the default function runs. + ''' + This combinator works like a case statement. It expects a single quote + on the stack that must contain zero or more condition quotes and a + default quote. Each condition clause should contain a quoted predicate + followed by the function expression to run if that predicate returns + true. If no predicates return true the default function runs. - It works by rewriting into a chain of nested `ifte` expressions, e.g.:: + It works by rewriting into a chain of nested `ifte` expressions, e.g.:: - [[[B0] T0] [[B1] T1] [D]] cond - ----------------------------------------- - [B0] [T0] [[B1] [T1] [D] ifte] ifte + [[[B0] T0] [[B1] T1] [D]] cond + ----------------------------------------- + [B0] [T0] [[B1] [T1] [D] ifte] ifte - ''' - conditions, stack = stack - if conditions: - expression = _cond(conditions, expression) - try: - # Attempt to preload the args to first ifte. - (P, (T, (E, expression))) = expression - except ValueError: - # If, for any reason, the argument to cond should happen to contain - # only the default clause then this optimization will fail. - pass - else: - stack = (E, (T, (P, stack))) - return stack, expression, dictionary
    + ''' + conditions, stack = stack + if conditions: + expression = _cond(conditions, expression) + try: + # Attempt to preload the args to first ifte. + (P, (T, (E, expression))) = expression + except ValueError: + # If, for any reason, the argument to cond should happen to contain + # only the default clause then this optimization will fail. + pass + else: + stack = (E, (T, (P, stack))) + return stack, expression, dictionary def _cond(conditions, expression): - (clause, rest) = conditions - if not rest: # clause is [D] - return clause - P, T = clause - return (P, (T, (_cond(rest, ()), (S_ifte, expression)))) + (clause, rest) = conditions + if not rest: # clause is [D] + return clause + P, T = clause + return (P, (T, (_cond(rest, ()), (S_ifte, expression))))
    [docs]@inscribe +@combinator_effect(_COMB_NUMS(), a1, s1) @FunctionWrapper def dip(stack, expression, dictionary): - ''' - The dip combinator expects a quoted program on the stack and below it - some item, it hoists the item into the expression and runs the program - on the rest of the stack. - :: + ''' + The dip combinator expects a quoted program on the stack and below it + some item, it hoists the item into the expression and runs the program + on the rest of the stack. + :: - ... x [Q] dip - ------------------- - ... Q x + ... x [Q] dip + ------------------- + ... Q x - ''' - (quote, (x, stack)) = stack - expression = (x, expression) - return stack, concat(quote, expression), dictionary
    + ''' + (quote, (x, stack)) = stack + expression = (x, expression) + return stack, concat(quote, expression), dictionary
    [docs]@inscribe +@combinator_effect(_COMB_NUMS(), a2, a1, s1) @FunctionWrapper def dipd(S, expression, dictionary): - ''' - Like dip but expects two items. - :: + ''' + Like dip but expects two items. + :: - ... y x [Q] dip - --------------------- - ... Q y x + ... y x [Q] dip + --------------------- + ... Q y x - ''' - (quote, (x, (y, stack))) = S - expression = (y, (x, expression)) - return stack, concat(quote, expression), dictionary
    + ''' + (quote, (x, (y, stack))) = S + expression = (y, (x, expression)) + return stack, concat(quote, expression), dictionary
    [docs]@inscribe +@combinator_effect(_COMB_NUMS(), a3, a2, a1, s1) @FunctionWrapper def dipdd(S, expression, dictionary): - ''' - Like dip but expects three items. - :: + ''' + Like dip but expects three items. + :: - ... z y x [Q] dip - ----------------------- - ... Q z y x + ... z y x [Q] dip + ----------------------- + ... Q z y x - ''' - (quote, (x, (y, (z, stack)))) = S - expression = (z, (y, (x, expression))) - return stack, concat(quote, expression), dictionary
    + ''' + (quote, (x, (y, (z, stack)))) = S + expression = (z, (y, (x, expression))) + return stack, concat(quote, expression), dictionary
    [docs]@inscribe +@combinator_effect(_COMB_NUMS(), a1, s1) @FunctionWrapper def app1(S, expression, dictionary): - ''' - Given a quoted program on TOS and anything as the second stack item run - the program and replace the two args with the first result of the - program. - :: + ''' + Given a quoted program on TOS and anything as the second stack item run + the program and replace the two args with the first result of the + program. + :: - ... x [Q] . app1 - ----------------------------------- - ... [x ...] [Q] . infra first - ''' - (quote, (x, stack)) = S - stack = (quote, ((x, stack), stack)) - expression = (S_infra, (S_first, expression)) - return stack, expression, dictionary
    + ... x [Q] . app1 + ----------------------------------- + ... [x ...] [Q] . infra first + ''' + (quote, (x, stack)) = S + stack = (quote, ((x, stack), stack)) + expression = (S_infra, (S_first, expression)) + return stack, expression, dictionary
    [docs]@inscribe +@combinator_effect(_COMB_NUMS(), a2, a1, s1) @FunctionWrapper def app2(S, expression, dictionary): - '''Like app1 with two items. - :: + '''Like app1 with two items. + :: - ... y x [Q] . app2 - ----------------------------------- - ... [y ...] [Q] . infra first - [x ...] [Q] infra first + ... y x [Q] . app2 + ----------------------------------- + ... [y ...] [Q] . infra first + [x ...] [Q] infra first - ''' - (quote, (x, (y, stack))) = S - expression = (S_infra, (S_first, - ((x, stack), (quote, (S_infra, (S_first, - expression)))))) - stack = (quote, ((y, stack), stack)) - return stack, expression, dictionary
    + ''' + (quote, (x, (y, stack))) = S + expression = (S_infra, (S_first, + ((x, stack), (quote, (S_infra, (S_first, + expression)))))) + stack = (quote, ((y, stack), stack)) + return stack, expression, dictionary
    [docs]@inscribe +@combinator_effect(_COMB_NUMS(), a3, a2, a1, s1) @FunctionWrapper def app3(S, expression, dictionary): - '''Like app1 with three items. - :: + '''Like app1 with three items. + :: - ... z y x [Q] . app3 - ----------------------------------- - ... [z ...] [Q] . infra first - [y ...] [Q] infra first - [x ...] [Q] infra first + ... z y x [Q] . app3 + ----------------------------------- + ... [z ...] [Q] . infra first + [y ...] [Q] infra first + [x ...] [Q] infra first - ''' - (quote, (x, (y, (z, stack)))) = S - expression = (S_infra, (S_first, - ((y, stack), (quote, (S_infra, (S_first, - ((x, stack), (quote, (S_infra, (S_first, - expression)))))))))) - stack = (quote, ((z, stack), stack)) - return stack, expression, dictionary
    + ''' + (quote, (x, (y, (z, stack)))) = S + expression = (S_infra, (S_first, + ((y, stack), (quote, (S_infra, (S_first, + ((x, stack), (quote, (S_infra, (S_first, + expression)))))))))) + stack = (quote, ((z, stack), stack)) + return stack, expression, dictionary
    [docs]@inscribe +@combinator_effect(_COMB_NUMS(), s7, s6) @FunctionWrapper def step(S, expression, dictionary): - ''' - Run a quoted program on each item in a sequence. - :: + ''' + Run a quoted program on each item in a sequence. + :: - ... [] [Q] . step - ----------------------- - ... . + ... [] [Q] . step + ----------------------- + ... . - ... [a] [Q] . step - ------------------------ - ... a . Q + ... [a] [Q] . step + ------------------------ + ... a . Q - ... [a b c] [Q] . step - ---------------------------------------- - ... a . Q [b c] [Q] step + ... [a b c] [Q] . step + ---------------------------------------- + ... a . Q [b c] [Q] step - The step combinator executes the quotation on each member of the list - on top of the stack. - ''' - (quote, (aggregate, stack)) = S - if not aggregate: - return stack, expression, dictionary - head, tail = aggregate - stack = quote, (head, stack) - if tail: - expression = tail, (quote, (S_step, expression)) - expression = S_i, expression - return stack, expression, dictionary
    + The step combinator executes the quotation on each member of the list + on top of the stack. + ''' + (quote, (aggregate, stack)) = S + if not aggregate: + return stack, expression, dictionary + head, tail = aggregate + stack = quote, (head, stack) + if tail: + expression = tail, (quote, (S_step, expression)) + expression = S_i, expression + return stack, expression, dictionary
    [docs]@inscribe +@combinator_effect(_COMB_NUMS(), i1, s6) @FunctionWrapper def times(stack, expression, dictionary): - ''' - times == [-- dip] cons [swap] infra [0 >] swap while pop - :: + ''' + times == [-- dip] cons [swap] infra [0 >] swap while pop + :: - ... n [Q] . times - --------------------- w/ n <= 0 - ... . + ... n [Q] . times + --------------------- w/ n <= 0 + ... . - ... 1 [Q] . times - --------------------------------- - ... . Q + ... 1 [Q] . times + --------------------------------- + ... . Q - ... n [Q] . times - --------------------------------- w/ n > 1 - ... . Q (n - 1) [Q] times + ... n [Q] . times + --------------------------------- w/ n > 1 + ... . Q (n - 1) [Q] times - ''' - # times == [-- dip] cons [swap] infra [0 >] swap while pop - (quote, (n, stack)) = stack - if n <= 0: - return stack, expression, dictionary - n -= 1 - if n: - expression = n, (quote, (S_times, expression)) - expression = concat(quote, expression) - return stack, expression, dictionary
    + ''' + # times == [-- dip] cons [swap] infra [0 >] swap while pop + (quote, (n, stack)) = stack + if n <= 0: + return stack, expression, dictionary + n -= 1 + if n: + expression = n, (quote, (S_times, expression)) + expression = concat(quote, expression) + return stack, expression, dictionary # The current definition above works like this: @@ -1261,51 +1456,66 @@ # return stack, expression, dictionary +def loop_true(stack, expression, dictionary): + quote, (flag, stack) = stack # pylint: disable=unused-variable + return stack, concat(quote, (S_pop, expression)), dictionary + +def loop_two_true(stack, expression, dictionary): + quote, (flag, stack) = stack # pylint: disable=unused-variable + return stack, concat(quote, (S_pop, concat(quote, (S_pop, expression)))), dictionary + +def loop_false(stack, expression, dictionary): + quote, (flag, stack) = stack # pylint: disable=unused-variable + return stack, expression, dictionary + +
    [docs]@inscribe +@poly_combinator_effect(_COMB_NUMS(), [loop_two_true, loop_true, loop_false], b1, s6) @FunctionWrapper def loop(stack, expression, dictionary): - ''' - Basic loop combinator. - :: + ''' + Basic loop combinator. + :: - ... True [Q] loop - ----------------------- - ... Q [Q] loop + ... True [Q] loop + ----------------------- + ... Q [Q] loop - ... False [Q] loop - ------------------------ - ... + ... False [Q] loop + ------------------------ + ... - ''' - quote, (flag, stack) = stack - if flag: - expression = concat(quote, (quote, (S_loop, expression))) - return stack, expression, dictionary
    + ''' + quote, (flag, stack) = stack + if flag: + expression = concat(quote, (quote, (S_loop, expression))) + return stack, expression, dictionary
    [docs]@inscribe +@combinator_effect(_COMB_NUMS(), a1, a2, s6, s7, s8) @FunctionWrapper def cmp_(stack, expression, dictionary): - ''' - cmp takes two values and three quoted programs on the stack and runs - one of the three depending on the results of comparing the two values: - :: + ''' + cmp takes two values and three quoted programs on the stack and runs + one of the three depending on the results of comparing the two values: + :: - a b [G] [E] [L] cmp - ------------------------- a > b - G + a b [G] [E] [L] cmp + ------------------------- a > b + G - a b [G] [E] [L] cmp - ------------------------- a = b - E + a b [G] [E] [L] cmp + ------------------------- a = b + E - a b [G] [E] [L] cmp - ------------------------- a < b - L - ''' - L, (E, (G, (b, (a, stack)))) = stack - expression = concat(G if a > b else L if a < b else E, expression) - return stack, expression, dictionary
    + a b [G] [E] [L] cmp + ------------------------- a < b + L + ''' + L, (E, (G, (b, (a, stack)))) = stack + expression = concat(G if a > b else L if a < b else E, expression) + return stack, expression, dictionary # FunctionWrapper(cleave), @@ -1313,41 +1523,141 @@ for F in ( - BinaryBuiltinWrapper(operator.add), - BinaryBuiltinWrapper(operator.and_), - BinaryBuiltinWrapper(operator.div), - BinaryBuiltinWrapper(operator.eq), - BinaryBuiltinWrapper(operator.floordiv), - BinaryBuiltinWrapper(operator.ge), - BinaryBuiltinWrapper(operator.gt), - BinaryBuiltinWrapper(operator.le), - BinaryBuiltinWrapper(operator.lshift), - BinaryBuiltinWrapper(operator.lt), - BinaryBuiltinWrapper(operator.mod), - BinaryBuiltinWrapper(operator.mul), - BinaryBuiltinWrapper(operator.ne), - BinaryBuiltinWrapper(operator.or_), - BinaryBuiltinWrapper(operator.pow), - BinaryBuiltinWrapper(operator.rshift), - BinaryBuiltinWrapper(operator.sub), - BinaryBuiltinWrapper(operator.truediv), - BinaryBuiltinWrapper(operator.xor), - UnaryBuiltinWrapper(abs), - UnaryBuiltinWrapper(bool), - UnaryBuiltinWrapper(floor), - UnaryBuiltinWrapper(operator.neg), - UnaryBuiltinWrapper(operator.not_), - UnaryBuiltinWrapper(sqrt), - ): - inscribe(F) + #divmod_ = pm = __(n2, n1), __(n4, n3) + + sec_binary_cmp(BinaryBuiltinWrapper(operator.eq)), + sec_binary_cmp(BinaryBuiltinWrapper(operator.ge)), + sec_binary_cmp(BinaryBuiltinWrapper(operator.gt)), + sec_binary_cmp(BinaryBuiltinWrapper(operator.le)), + sec_binary_cmp(BinaryBuiltinWrapper(operator.lt)), + sec_binary_cmp(BinaryBuiltinWrapper(operator.ne)), + + sec_binary_ints(BinaryBuiltinWrapper(operator.xor)), + sec_binary_ints(BinaryBuiltinWrapper(operator.lshift)), + sec_binary_ints(BinaryBuiltinWrapper(operator.rshift)), + + sec_binary_logic(BinaryBuiltinWrapper(operator.and_)), + sec_binary_logic(BinaryBuiltinWrapper(operator.or_)), + + sec_binary_math(BinaryBuiltinWrapper(operator.add)), + sec_binary_math(BinaryBuiltinWrapper(operator.floordiv)), + sec_binary_math(BinaryBuiltinWrapper(operator.mod)), + sec_binary_math(BinaryBuiltinWrapper(operator.mul)), + sec_binary_math(BinaryBuiltinWrapper(operator.pow)), + sec_binary_math(BinaryBuiltinWrapper(operator.sub)), + sec_binary_math(BinaryBuiltinWrapper(operator.truediv)), + + sec_unary_logic(UnaryBuiltinWrapper(bool)), + sec_unary_logic(UnaryBuiltinWrapper(operator.not_)), + + sec_unary_math(UnaryBuiltinWrapper(abs)), + sec_unary_math(UnaryBuiltinWrapper(operator.neg)), + sec_unary_math(UnaryBuiltinWrapper(sqrt)), + + stack_effect(n1)(i1)(UnaryBuiltinWrapper(floor)), + ): + inscribe(F) del F # Otherwise Sphinx autodoc will pick it up. +YIN_STACK_EFFECTS = yin_functions() +add_aliases(YIN_STACK_EFFECTS, ALIASES) + +# Load the auto-generated primitives into the dictionary. +_functions.update(YIN_STACK_EFFECTS) +# exec ''' + +# eh = compose(dup, bool) +# sqr = compose(dup, mul) +# of = compose(swap, at) + +# ''' in dict(compose=compose), _functions +for name in sorted(_functions): + sec = _functions[name] + F = FUNCTIONS[name] = SymbolJoyType(name, [sec], _SYM_NUMS()) + if name in YIN_STACK_EFFECTS: + _log.info('Setting stack effect for Yin function %s := %s', F.name, doc_from_stack_effect(*sec)) + +for name, primitive in getmembers(genlib, isfunction): + inscribe(SimpleFunctionWrapper(primitive)) + + add_aliases(_dictionary, ALIASES) +add_aliases(_functions, ALIASES) +add_aliases(FUNCTIONS, ALIASES) DefinitionWrapper.add_definitions(definitions, _dictionary) + + +EXPECTATIONS = dict( + ifte=(s7, (s6, (s5, s4))), + nullary=(s7, s6), + run=(s7, s6), +) +EXPECTATIONS['while'] = (s7, (s6, s5)) + + +for name in ''' + dinfrirst + nullary + ifte + run + dupdipd codireco + while + '''.split(): + C = _dictionary[name] + expect = EXPECTATIONS.get(name) + if expect: + sec = doc_from_stack_effect(expect) + _log.info('Setting stack EXPECT for combinator %s := %s', C.name, sec) + else: + _log.info('combinator %s', C.name) + FUNCTIONS[name] = CombinatorJoyType(name, [C], _COMB_NUMS(), expect) + + +for name in (''' + of quoted enstacken ? + unary binary ternary + sqr unquoted + '''.split()): + of_ = _dictionary[name] + secs = infer_expression(of_.body) + assert len(secs) == 1, repr(secs) + _log.info( + 'Setting stack effect for definition %s := %s', + name, + doc_from_stack_effect(*secs[0]), + ) + FUNCTIONS[name] = SymbolJoyType(name, infer_expression(of_.body), _SYM_NUMS()) + + +#sec_Ns_math(_dictionary['product']) + +## product == 1 swap [*] step +## flatten == [] swap [concat] step +## disenstacken == ? [uncons ?] loop pop +## pam == [i] map +## size == 0 swap [pop ++] step +## fork == [i] app2 +## cleave == fork [popd] dip +## average == [sum 1.0 *] [size] cleave / +## gcd == 1 [tuck modulus dup 0 >] loop pop +## least_fraction == dup [gcd] infra [div] concat map +## *fraction == [uncons] dip uncons [swap] dip concat [*] infra [*] dip cons +## *fraction0 == concat [[swap] dip * [*] dip] infra +## down_to_zero == [0 >] [dup --] while +## range_to_zero == unit [down_to_zero] infra +## anamorphism == [pop []] swap [dip swons] genrec +## range == [0 <=] [1 - dup] anamorphism +## while == swap [nullary] cons dup dipd concat loop +## dupdipd == dup dipd +## primrec == [i] genrec +## step_zero == 0 roll> step +## codireco == cons dip rest cons +## make_generator == [codireco] ccons +## ifte == [nullary not] dipd branch diff --git a/docs/sphinx_docs/_build/html/_modules/joy/parser.html b/docs/sphinx_docs/_build/html/_modules/joy/parser.html index 20ee021..6431c2f 100644 --- a/docs/sphinx_docs/_build/html/_modules/joy/parser.html +++ b/docs/sphinx_docs/_build/html/_modules/joy/parser.html @@ -59,90 +59,102 @@ A crude grammar:: - joy = term* - term = int | float | string | '[' joy ']' | function - -A Joy expression is a sequence of zero or more terms + joy = term* + term = int | float | string | '[' joy ']' | symbol +A Joy expression is a sequence of zero or more terms. A term is a +literal value (integer, float, string, or Joy expression) or a function +symbol. Function symbols are unquoted strings and cannot contain square +brackets. Terms must be separated by blanks, which can be omitted +around square brackets. ''' -#TODO: explain the details of float lits and strings. from re import Scanner from .utils.stack import list_to_stack +#TODO: explain the details of float lits and strings. +FLOAT = r'-?\d+\.\d*' +INT = r'-?\d+' +SYMBOL = r'[•\w!@$%^&*()_+<>?|\/;:`~,.=-]+' +BRACKETS = r'\[|\]' +STRING_DOUBLE_QUOTED = r'"(?:[^"\\]|\\.)*"' +STRING_SINGLE_QUOTED = r"'(?:[^'\\]|\\.)*'" +BLANKS = r'\s+' + +
    [docs]class Symbol(str): - '''A string class that represents Joy function names.''' - __repr__ = str.__str__
    + '''A string class that represents Joy function names.''' + __repr__ = str.__str__
    [docs]def text_to_expression(text): - '''Convert a string to a Joy expression. + '''Convert a string to a Joy expression. - When supplied with a string this function returns a Python datastructure - that represents the Joy datastructure described by the text expression. - Any unbalanced square brackets will raise a ParseError. + When supplied with a string this function returns a Python datastructure + that represents the Joy datastructure described by the text expression. + Any unbalanced square brackets will raise a ParseError. - :param str text: Text to convert. - :rtype: stack - :raises ParseError: if the parse fails. - ''' - return _parse(_tokenize(text))
    + :param str text: Text to convert. + :rtype: stack + :raises ParseError: if the parse fails. + ''' + return _parse(_tokenize(text))
    [docs]class ParseError(ValueError): - '''Raised when there is a error while parsing text.'''
    + '''Raised when there is a error while parsing text.''' def _tokenize(text): - '''Convert a text into a stream of tokens. + '''Convert a text into a stream of tokens. - Converts function names to Symbols. + Converts function names to Symbols. - Raise ParseError (with some of the failing text) if the scan fails. - ''' - tokens, rest = _scanner.scan(text) - if rest: - raise ParseError( - 'Scan failed at position %i, %r' - % (len(text) - len(rest), rest[:10]) - ) - return tokens + Raise ParseError (with some of the failing text) if the scan fails. + ''' + tokens, rest = _scanner.scan(text) + if rest: + raise ParseError( + 'Scan failed at position %i, %r' + % (len(text) - len(rest), rest[:10]) + ) + return tokens def _parse(tokens): - ''' - Return a stack/list expression of the tokens. - ''' - frame = [] - stack = [] - for tok in tokens: - if tok == '[': - stack.append(frame) - frame = [] - stack[-1].append(frame) - elif tok == ']': - try: - frame = stack.pop() - except IndexError: - raise ParseError('Extra closing bracket.') - frame[-1] = list_to_stack(frame[-1]) - else: - frame.append(tok) - if stack: - raise ParseError('Unclosed bracket.') - return list_to_stack(frame) + ''' + Return a stack/list expression of the tokens. + ''' + frame = [] + stack = [] + for tok in tokens: + if tok == '[': + stack.append(frame) + frame = [] + stack[-1].append(frame) + elif tok == ']': + try: + frame = stack.pop() + except IndexError: + raise ParseError('Extra closing bracket.') + frame[-1] = list_to_stack(frame[-1]) + else: + frame.append(tok) + if stack: + raise ParseError('Unclosed bracket.') + return list_to_stack(frame) _scanner = Scanner([ - (r'-?\d+\.\d*', lambda _, token: float(token)), - (r'-?\d+', lambda _, token: int(token)), - (r'[•\w!@$%^&*()_+<>?|\/;:`~,.=-]+', lambda _, token: Symbol(token)), - (r'\[|\]', lambda _, token: token), - (r'"(?:[^"\\]|\\.)*"', lambda _, token: token[1:-1].replace('\\"', '"')), - (r"'(?:[^'\\]|\\.)*'", lambda _, token: token[1:-1].replace("\\'", "'")), - (r'\s+', None), - ]) + (FLOAT, lambda _, token: float(token)), + (INT, lambda _, token: int(token)), + (SYMBOL, lambda _, token: Symbol(token)), + (BRACKETS, lambda _, token: token), + (STRING_DOUBLE_QUOTED, lambda _, token: token[1:-1].replace('\\"', '"')), + (STRING_SINGLE_QUOTED, lambda _, token: token[1:-1].replace("\\'", "'")), + (BLANKS, None), + ]) diff --git a/docs/sphinx_docs/_build/html/_modules/joy/utils/pretty_print.html b/docs/sphinx_docs/_build/html/_modules/joy/utils/pretty_print.html index 6f24681..49bcd72 100644 --- a/docs/sphinx_docs/_build/html/_modules/joy/utils/pretty_print.html +++ b/docs/sphinx_docs/_build/html/_modules/joy/utils/pretty_print.html @@ -73,62 +73,63 @@ # (Kinda clunky and hacky. This should be swapped out in favor of much # smarter stuff.) from __future__ import print_function +from builtins import object from traceback import print_exc from .stack import expression_to_string, stack_to_string
    [docs]class TracePrinter(object): - ''' - This is what does the formatting. You instantiate it and pass the ``viewer()`` - method to the :py:func:`joy.joy.joy` function, then print it to see the - trace. - ''' + ''' + This is what does the formatting. You instantiate it and pass the ``viewer()`` + method to the :py:func:`joy.joy.joy` function, then print it to see the + trace. + ''' - def __init__(self): - self.history = [] + def __init__(self): + self.history = [] -
    [docs] def viewer(self, stack, expression): - ''' - Record the current stack and expression in the TracePrinter's history. - Pass this method as the ``viewer`` argument to the :py:func:`joy.joy.joy` function. +
    [docs] def viewer(self, stack, expression): + ''' + Record the current stack and expression in the TracePrinter's history. + Pass this method as the ``viewer`` argument to the :py:func:`joy.joy.joy` function. - :param stack quote: A stack. - :param stack expression: A stack. - ''' - self.history.append((stack, expression))
    + :param stack quote: A stack. + :param stack expression: A stack. + ''' + self.history.append((stack, expression))
    - def __str__(self): - return '\n'.join(self.go()) + def __str__(self): + return '\n'.join(self.go()) -
    [docs] def go(self): - ''' - Return a list of strings, one for each entry in the history, prefixed - with enough spaces to align all the interpreter dots. +
    [docs] def go(self): + ''' + Return a list of strings, one for each entry in the history, prefixed + with enough spaces to align all the interpreter dots. - This method is called internally by the ``__str__()`` method. + This method is called internally by the ``__str__()`` method. - :rtype: list(str) - ''' - max_stack_length = 0 - lines = [] - for stack, expression in self.history: - stack = stack_to_string(stack) - expression = expression_to_string(expression) - n = len(stack) - if n > max_stack_length: - max_stack_length = n - lines.append((n, '%s . %s' % (stack, expression))) - return [ # Prefix spaces to line up '.'s. - (' ' * (max_stack_length - length) + line) - for length, line in lines - ]
    + :rtype: list(str) + ''' + max_stack_length = 0 + lines = [] + for stack, expression in self.history: + stack = stack_to_string(stack) + expression = expression_to_string(expression) + n = len(stack) + if n > max_stack_length: + max_stack_length = n + lines.append((n, '%s . %s' % (stack, expression))) + return [ # Prefix spaces to line up '.'s. + (' ' * (max_stack_length - length) + line) + for length, line in lines + ]
    - def print_(self): - try: - print(self) - except: - print_exc() - print('Exception while printing viewer.')
    + def print_(self): + try: + print(self) + except: + print_exc() + print('Exception while printing viewer.') diff --git a/docs/sphinx_docs/_build/html/_modules/joy/utils/stack.html b/docs/sphinx_docs/_build/html/_modules/joy/utils/stack.html index 789b936..bf52069 100644 --- a/docs/sphinx_docs/_build/html/_modules/joy/utils/stack.html +++ b/docs/sphinx_docs/_build/html/_modules/joy/utils/stack.html @@ -76,8 +76,8 @@ For example:: - def dup((head, tail)): - return head, (head, tail) + def dup((head, tail)): + return head, (head, tail) We replace the argument "stack" by the expected structure of the stack, in this case "(head, tail)", and Python takes care of unpacking the @@ -89,9 +89,9 @@ web page, doesn't handle tuples in the function parameters. And in Python 3, this syntax was removed entirely. Instead you would have to write:: - def dup(stack): - head, tail = stack - return head, (head, tail) + def dup(stack): + head, tail = stack + return head, (head, tail) We have two very simple functions, one to build up a stack from a Python @@ -105,98 +105,97 @@ ''' +from builtins import map
    [docs]def list_to_stack(el, stack=()): - '''Convert a Python list (or other sequence) to a Joy stack:: + '''Convert a Python list (or other sequence) to a Joy stack:: - [1, 2, 3] -> (1, (2, (3, ()))) + [1, 2, 3] -> (1, (2, (3, ()))) - :param list el: A Python list or other sequence (iterators and generators - won't work because ``reverse()`` is called on ``el``.) - :param stack stack: A stack, optional, defaults to the empty stack. - :rtype: stack + :param list el: A Python list or other sequence (iterators and generators + won't work because ``reverse()`` is called on ``el``.) + :param stack stack: A stack, optional, defaults to the empty stack. + :rtype: stack - ''' - for item in reversed(el): - stack = item, stack - return stack
    + ''' + for item in reversed(el): + stack = item, stack + return stack
    [docs]def iter_stack(stack): - '''Iterate through the items on the stack. + '''Iterate through the items on the stack. - :param stack stack: A stack. - :rtype: iterator - ''' - while stack: - item, stack = stack - yield item
    + :param stack stack: A stack. + :rtype: iterator + ''' + while stack: + item, stack = stack + yield item
    [docs]def stack_to_string(stack): - ''' - Return a "pretty print" string for a stack. + ''' + Return a "pretty print" string for a stack. - The items are written right-to-left:: + The items are written right-to-left:: - (top, (second, ...)) -> '... second top' + (top, (second, ...)) -> '... second top' - :param stack stack: A stack. - :rtype: str - ''' - f = lambda stack: reversed(list(iter_stack(stack))) - return _to_string(stack, f)
    + :param stack stack: A stack. + :rtype: str + ''' + f = lambda stack: reversed(list(iter_stack(stack))) + return _to_string(stack, f)
    [docs]def expression_to_string(expression): - ''' - Return a "pretty print" string for a expression. + ''' + Return a "pretty print" string for a expression. - The items are written left-to-right:: + The items are written left-to-right:: - (top, (second, ...)) -> 'top second ...' + (top, (second, ...)) -> 'top second ...' - :param stack expression: A stack. - :rtype: str - ''' - return _to_string(expression, iter_stack)
    + :param stack expression: A stack. + :rtype: str + ''' + return _to_string(expression, iter_stack) def _to_string(stack, f): - if isinstance(stack, long): return str(stack).rstrip('L') - if not isinstance(stack, tuple): return repr(stack) - if not stack: return '' # shortcut - return ' '.join(map(_s, f(stack))) + if not isinstance(stack, tuple): return repr(stack) + if not stack: return '' # shortcut + return ' '.join(map(_s, f(stack))) _s = lambda s: ( - '[%s]' % expression_to_string(s) if isinstance(s, tuple) - else str(s).rstrip('L') if isinstance(s, long) - else repr(s) - ) + '[%s]' % expression_to_string(s) if isinstance(s, tuple) + else repr(s) + )
    [docs]def concat(quote, expression): - '''Concatinate quote onto expression. + '''Concatinate quote onto expression. - In joy [1 2] [3 4] would become [1 2 3 4]. + In joy [1 2] [3 4] would become [1 2 3 4]. - :param stack quote: A stack. - :param stack expression: A stack. - :raises RuntimeError: if quote is larger than sys.getrecursionlimit(). - :rtype: stack - ''' - # This is the fastest implementation, but will trigger - # RuntimeError: maximum recursion depth exceeded - # on quotes longer than sys.getrecursionlimit(). + :param stack quote: A stack. + :param stack expression: A stack. + :raises RuntimeError: if quote is larger than sys.getrecursionlimit(). + :rtype: stack + ''' + # This is the fastest implementation, but will trigger + # RuntimeError: maximum recursion depth exceeded + # on quotes longer than sys.getrecursionlimit(). - return (quote[0], concat(quote[1], expression)) if quote else expression
    + return (quote[0], concat(quote[1], expression)) if quote else expression - # Original implementation. + # Original implementation. ## return list_to_stack(list(iter_stack(quote)), expression) - # In-lining is slightly faster (and won't break the - # recursion limit on long quotes.) + # In-lining is slightly faster (and won't break the + # recursion limit on long quotes.) ## temp = [] ## while quote: @@ -208,27 +207,27 @@ -
    [docs]def pick(s, n): - ''' - Return the nth item on the stack. +
    [docs]def pick(stack, n): + ''' + Return the nth item on the stack. - :param stack s: A stack. - :param int n: An index into the stack. - :raises ValueError: if ``n`` is less than zero. - :raises IndexError: if ``n`` is equal to or greater than the length of ``s``. - :rtype: whatever - ''' - if n < 0: - raise ValueError - while True: - try: - item, s = s - except ValueError: - raise IndexError - n -= 1 - if n < 0: - break - return item
    + :param stack stack: A stack. + :param int n: An index into the stack. + :raises ValueError: if ``n`` is less than zero. + :raises IndexError: if ``n`` is equal to or greater than the length of ``stack``. + :rtype: whatever + ''' + if n < 0: + raise ValueError + while True: + try: + item, stack = stack + except ValueError: + raise IndexError + n -= 1 + if n < 0: + break + return item
    diff --git a/docs/sphinx_docs/_build/html/genindex.html b/docs/sphinx_docs/_build/html/genindex.html index 37e4c73..1abd3b6 100644 --- a/docs/sphinx_docs/_build/html/genindex.html +++ b/docs/sphinx_docs/_build/html/genindex.html @@ -58,6 +58,7 @@ | V | W | X + | Y | Z @@ -72,6 +73,8 @@
  • (joy.utils.types.IntJoyType attribute)
  • (joy.utils.types.StackJoyType attribute) +
  • +
  • (joy.utils.types.TextJoyType attribute)
  • add_aliases() (in module joy.library) @@ -120,7 +123,7 @@
  • cmp_() (in module joy.library)
  • -
  • CombinatorJoyType (class in joy.utils.polytypes) +
  • CombinatorJoyType (class in joy.utils.types)
  • compilable() (in module joy.utils.types)
  • @@ -128,12 +131,8 @@ @@ -463,6 +454,8 @@
  • take() (in module joy.library)
  • text_to_expression() (in module joy.parser) +
  • +
  • TextJoyType (class in joy.utils.types)
  • third() (in module joy.utils.generated_library)
  • @@ -474,7 +467,7 @@
  • tuck() (in module joy.utils.generated_library)
  • -
  • type_check() (in module joy.utils.polytypes) +
  • type_check() (in module joy.utils.types)
  • @@ -486,7 +479,7 @@
  • uncons() (in module joy.utils.generated_library)
  • -
  • unify() (in module joy.utils.types) +
  • uni_unify() (in module joy.utils.types)
  • +

    Y

    + + +
    +

    Z

      diff --git a/docs/sphinx_docs/_build/html/joy.html b/docs/sphinx_docs/_build/html/joy.html index d5d82a1..87363f6 100644 --- a/docs/sphinx_docs/_build/html/joy.html +++ b/docs/sphinx_docs/_build/html/joy.html @@ -42,11 +42,13 @@ match the behaviour of the original version(s) written in C.

      joy.joy.joy(stack, expression, dictionary, viewer=None)[source]
      -

      Evaluate the Joy expression on the stack.

      -

      The basic joy() function is quite straightforward. It iterates through a -sequence of terms which are either literals (strings, numbers, sequences) -or functions. Literals are put onto the stack and functions are -executed.

      +

      Evaluate a Joy expression on a stack.

      +

      This function iterates through a sequence of terms which are either +literals (strings, numbers, sequences of terms) or function symbols. +Literals are put onto the stack and functions are looked up in the +disctionary and executed.

      +

      The viewer is a function that is called with the stack and expression +on every iteration, its return value is ignored.

      diff --git a/docs/sphinx_docs/_build/html/library.html b/docs/sphinx_docs/_build/html/library.html index 2571a27..98c511f 100644 --- a/docs/sphinx_docs/_build/html/library.html +++ b/docs/sphinx_docs/_build/html/library.html @@ -52,7 +52,7 @@ function.

      Provide implementation of defined functions, and some helper methods.

      -classmethod add_def(definition, dictionary)[source]
      +classmethod add_def(definition, dictionary, fail_fails=False)[source]

      Add the definition to the dictionary.

      @@ -104,9 +104,9 @@ if it’s in the dict. Aliases for functions not in the dict are ignored.

      Given a quoted program on TOS and anything as the second stack item run the program and replace the two args with the first result of the program.

      -
               ... x [Q] . app1
      +
                                             ... x [Q] . app1
       -----------------------------------
      -   ... [x ...] [Q] . infra first
      +               ... [x ...] [Q] . infra first
       
      @@ -115,10 +115,10 @@ program.

      joy.library.app2(S, expression, dictionary)[source]

      Like app1 with two items.

      -
             ... y x [Q] . app2
      +
                                     ... y x [Q] . app2
       -----------------------------------
      -   ... [y ...] [Q] . infra first
      -       [x ...] [Q]   infra first
      +               ... [y ...] [Q] . infra first
      +                               [x ...] [Q]   infra first
       
      @@ -127,11 +127,11 @@ program.

      joy.library.app3(S, expression, dictionary)[source]

      Like app1 with three items.

      -
             ... z y x [Q] . app3
      +
                                     ... z y x [Q] . app3
       -----------------------------------
      -   ... [z ...] [Q] . infra first
      -       [y ...] [Q]   infra first
      -       [x ...] [Q]   infra first
      +               ... [z ...] [Q] . infra first
      +                               [y ...] [Q]   infra first
      +                               [x ...] [Q]   infra first
       
      @@ -154,13 +154,13 @@ program.

      branch == roll< choice i
       
      -
         False [F] [T] branch
      +
                     False [F] [T] branch
       --------------------------
      -          F
      +                                        F
       
      -   True [F] [T] branch
      +               True [F] [T] branch
       -------------------------
      -             T
      +                                                       T
       
      @@ -169,14 +169,14 @@ program.

      joy.library.choice(stack, expression, dictionary)[source]

      Use a Boolean value to select one of two items.

      -
         A B False choice
      +
                     A B False choice
       ----------------------
      -          A
      +                                        A
       
       
      -   A B True choice
      +               A B True choice
       ---------------------
      -          B
      +                                        B
       

      Currently Python semantics are used to evaluate the “truthiness” of the @@ -189,7 +189,7 @@ Boolean value (so empty string, zero, etc. are counted as false, etc.)

      Clear everything from the stack.

      clear == stack [pop stack] loop
       
      -   ... clear
      +         ... clear
       ---------------
       
      @@ -200,17 +200,17 @@ Boolean value (so empty string, zero, etc. are counted as false, etc.)

      joy.library.cmp_(stack, expression, dictionary)[source]

      cmp takes two values and three quoted programs on the stack and runs one of the three depending on the results of comparing the two values:

      -
         a b [G] [E] [L] cmp
      +
               a b [G] [E] [L] cmp
       ------------------------- a > b
      -        G
      +                                G
       
      -   a b [G] [E] [L] cmp
      +         a b [G] [E] [L] cmp
       ------------------------- a = b
      -            E
      +                                                E
       
      -   a b [G] [E] [L] cmp
      +         a b [G] [E] [L] cmp
       ------------------------- a < b
      -                L
      +                                                                L
       
      @@ -219,9 +219,9 @@ one of the three depending on the results of comparing the two values:

      joy.library.concat_(stack, expression, dictionary)[source]

      Concatinate the two lists on the top of the stack.

      -
         [a b c] [d e f] concat
      +
               [a b c] [d e f] concat
       ----------------------------
      -       [a b c d e f]
      +                         [a b c d e f]
       
      @@ -235,9 +235,9 @@ default quote. Each condition clause should contain a quoted predicate followed by the function expression to run if that predicate returns true. If no predicates return true the default function runs.

      It works by rewriting into a chain of nested ifte expressions, e.g.:

      -
            [[[B0] T0] [[B1] T1] [D]] cond
      +
                              [[[B0] T0] [[B1] T1] [D]] cond
       -----------------------------------------
      -   [B0] [T0] [[B1] [T1] [D] ifte] ifte
      +         [B0] [T0] [[B1] [T1] [D] ifte] ifte
       
      @@ -248,9 +248,9 @@ true. If no predicates return true the default function runs.

      The dip combinator expects a quoted program on the stack and below it some item, it hoists the item into the expression and runs the program on the rest of the stack.

      -
         ... x [Q] dip
      +
               ... x [Q] dip
       -------------------
      -     ... Q x
      +                 ... Q x
       
      @@ -259,9 +259,9 @@ on the rest of the stack.

      joy.library.dipd(S, expression, dictionary)[source]

      Like dip but expects two items.

      -
         ... y x [Q] dip
      +
               ... y x [Q] dip
       ---------------------
      -     ... Q y x
      +                 ... Q y x
       
      @@ -270,9 +270,9 @@ on the rest of the stack.

      joy.library.dipdd(S, expression, dictionary)[source]

      Like dip but expects three items.

      -
         ... z y x [Q] dip
      +
               ... z y x [Q] dip
       -----------------------
      -     ... Q z y x
      +                 ... Q z y x
       
      @@ -287,14 +287,20 @@ on the rest of the stack.

      joy.library.drop(stack, expression, dictionary)[source]
      -
      drop == [rest] times
      +
      +
      drop == [rest] times
       

      Expects an integer and a quote on the stack and returns the quote with n items removed off the top.

      -
         [a b c d] 2 drop
      +
               [a b c d] 2 drop
       ----------------------
      -       [c d]
      +                         [c d]
      +
      +
      +
      +

      Stack effect:

      +
      ([...0] i1 -- [...1])
       
      @@ -323,9 +329,9 @@ This is the largest integral value <= x.

      joy.library.genrec(stack, expression, dictionary)[source]

      General Recursion Combinator.

      -
                            [if] [then] [rec1] [rec2] genrec
      +
                                                                                              [if] [then] [rec1] [rec2] genrec
       ---------------------------------------------------------------------
      -   [if] [then] [rec1 [[if] [then] [rec1] [rec2] genrec] rec2] ifte
      +         [if] [then] [rec1 [[if] [then] [rec1] [rec2] genrec] rec2] ifte
       

      From “Recursion Theory and Joy” (j05cmp.html) by Manfred von Thun: @@ -355,13 +361,13 @@ have to do to apply the quoted [F] in the proper way. In effect, the genrec combinator turns into an ifte combinator with a quoted copy of the original definition in the else-part:

      F == [I] [T] [R1]   [R2] genrec
      -  == [I] [T] [R1 [F] R2] ifte
      +        == [I] [T] [R1 [F] R2] ifte
       

      Primitive recursive functions are those where R2 == i.

      P == [I] [T] [R] primrec
      -  == [I] [T] [R [P] i] ifte
      -  == [I] [T] [R P] ifte
      +        == [I] [T] [R [P] i] ifte
      +        == [I] [T] [R P] ifte
       
      @@ -369,14 +375,20 @@ the original definition in the else-part:

      joy.library.getitem(stack, expression, dictionary)[source]
      -
      getitem == drop first
      +
      +
      getitem == drop first
       

      Expects an integer and a quote on the stack and returns the item at the nth position in the quote counting from 0.

      -
         [a b c d] 0 getitem
      +
               [a b c d] 0 getitem
       -------------------------
      -            a
      +                                                a
      +
      +
      +
      +

      Stack effect:

      +
      ([...0] i1 -- a1)
       
      @@ -392,9 +404,9 @@ nth position in the quote counting from 0.

      joy.library.i(stack, expression, dictionary)[source]

      The i combinator expects a quoted program on the stack and unpacks it onto the pending expression for evaluation.

      -
         [Q] i
      +
               [Q] i
       -----------
      -    Q
      +                Q
       
      @@ -405,14 +417,20 @@ onto the pending expression for evaluation.

      The identity function.

      +
      +
      +joy.library.infer_(stack, expression, dictionary)[source]
      +

      Attempt to infer the stack effect of a Joy expression.

      +
      +
      joy.library.infra(stack, expression, dictionary)[source]

      Accept a quoted program and a list on the stack and run the program -with the list as its stack.

      -
         ... [a b c] [Q] . infra
      +with the list as its stack.  Does not affect the rest of the stack.

      +
               ... [a b c] [Q] . infra
       -----------------------------
      -   c b a . Q [...] swaack
      +         c b a . Q [...] swaack
       
      @@ -429,17 +447,35 @@ with the list as its stack.

      A decorator to inscribe functions into the default dictionary.

      +
      +
      +joy.library.inscribe_(stack, expression, dictionary)[source]
      +
      +

      Create a new Joy function definition in the Joy dictionary. A +definition is given as a string with a name followed by a double +equal sign then one or more Joy functions, the body. for example:

      +
      +
      sqr == dup mul
      +

      If you want the definition to persist over restarts, enter it into +the definitions.txt resource.

      +
      +

      Stack effect:

      +
      (t1 --)
      +
      +
      +
      +
      joy.library.loop(stack, expression, dictionary)[source]

      Basic loop combinator.

      -
         ... True [Q] loop
      +
               ... True [Q] loop
       -----------------------
      -      ... Q [Q] loop
      +                        ... Q [Q] loop
       
      -   ... False [Q] loop
      +         ... False [Q] loop
       ------------------------
      -          ...
      +                                        ...
       
      @@ -448,19 +484,27 @@ with the list as its stack.

      joy.library.map_(S, expression, dictionary)[source]

      Run the quoted program on TOS on the items in the list under it, push a -new list with the results (in place of the program and original list.

      +new list with the results in place of the program and original list.

      joy.library.max_(stack, expression, dictionary)[source]
      -

      Given a list find the maximum.

      +

      Given a list find the maximum. +Stack effect:

      +
      ([n2* ...1] -- n0)
      +
      +
      joy.library.min_(stack, expression, dictionary)[source]
      -

      Given a list find the minimum.

      +

      Given a list find the minimum. +Stack effect:

      +
      ([n2* ...1] -- n0)
      +
      +
      @@ -473,9 +517,9 @@ new list with the results (in place of the program and original list.

      joy.library.pm(stack, expression, dictionary)[source]

      Plus or minus

      -
         a b pm
      +
               a b pm
       -------------
      -   a+b a-b
      +         a+b a-b
       
      @@ -483,7 +527,11 @@ new list with the results (in place of the program and original list.

      joy.library.pred(stack, expression, dictionary)[source]
      -

      Decrement TOS.

      +

      Decrement TOS. +Stack effect:

      +
      (n1 -- n2)
      +
      +
      @@ -491,9 +539,9 @@ new list with the results (in place of the program and original list.

      joy.library.remove(stack, expression, dictionary)[source]

      Expects an item on the stack and a quote under it and removes that item from the the quote. The item is only removed once.

      -
         [1 2 3 1] 1 remove
      +
               [1 2 3 1] 1 remove
       ------------------------
      -        [2 3 1]
      +                                [2 3 1]
       
      @@ -511,14 +559,14 @@ from the the quote. The item is only removed once.

      joy.library.select(stack, expression, dictionary)[source]

      Use a Boolean value to select one of two items from a sequence.

      -
         [A B] False select
      +
                     [A B] False select
       ------------------------
      -           A
      +                                               A
       
       
      -   [A B] True select
      +               [A B] True select
       -----------------------
      -          B
      +                                        B
       

      The sequence can contain more than two items but not fewer. @@ -538,9 +586,9 @@ Boolean value (so empty string, zero, etc. are counted as false, etc.)

      Like concat but reverses the top list into the second.

      shunt == [swons] step == reverse swap concat
       
      -   [a b c] [d e f] shunt
      +         [a b c] [d e f] shunt
       ---------------------------
      -     [f e d a b c] 
      +                 [f e d a b c] 
       
      @@ -562,19 +610,19 @@ Negative numbers return complex roots.

      joy.library.step(S, expression, dictionary)[source]

      Run a quoted program on each item in a sequence.

      -
            ... [] [Q] . step
      -   -----------------------
      -             ... .
      +
                              ... [] [Q] . step
      +         -----------------------
      +                                                 ... .
       
       
      -     ... [a] [Q] . step
      -  ------------------------
      -           ... a . Q
      +                 ... [a] [Q] . step
      +        ------------------------
      +                                         ... a . Q
       
       
      -   ... [a b c] [Q] . step
      +         ... [a b c] [Q] . step
       ----------------------------------------
      -             ... a . Q [b c] [Q] step
      +                                                 ... a . Q [b c] [Q] step
       

      The step combinator executes the quotation on each member of the list @@ -584,25 +632,40 @@ on top of the stack.

      joy.library.succ(stack, expression, dictionary)[source]
      -

      Increment TOS.

      +

      Increment TOS. +Stack effect:

      +
      (n1 -- n2)
      +
      +
      joy.library.sum_(stack, expression, dictionary)[source]

      Given a quoted sequence of numbers return the sum.

      -

      sum == 0 swap [+] step

      +
      +
      sum == 0 swap [+] step
      +

      Stack effect:

      +
      ([n2* ...1] -- n0)
      +
      +
      joy.library.take(stack, expression, dictionary)[source]
      -

      Expects an integer and a quote on the stack and returns the quote with +

      +

      Expects an integer and a quote on the stack and returns the quote with just the top n items in reverse order (because that’s easier and you can use reverse if needed.)

      -
         [a b c d] 2 take
      +
               [a b c d] 2 take
       ----------------------
      -       [b a]
      +                         [b a]
      +
      +
      +
      +

      Stack effect:

      +
      ([...0] i1 -- [...1])
       
      @@ -611,19 +674,19 @@ use reverse if needed.)

      joy.library.times(stack, expression, dictionary)[source]

      times == [– dip] cons [swap] infra [0 >] swap while pop

      -
         ... n [Q] . times
      +
               ... n [Q] . times
       ---------------------  w/ n <= 0
      -         ... .
      +                                 ... .
       
       
      -   ... 1 [Q] . times
      +         ... 1 [Q] . times
       ---------------------------------
      -         ... . Q
      +                                 ... . Q
       
       
      -   ... n [Q] . times
      +         ... n [Q] . times
       ---------------------------------  w/ n > 1
      -         ... . Q (n - 1) [Q] times
      +                                 ... . Q (n - 1) [Q] times
       
      @@ -671,6 +734,15 @@ the stack discarding the rest of the stack.

      +
      +
      +joy.library.yin_functions()[source]
      +

      Return a dict of named stack effects.

      +

      “Yin” functions are those that only rearrange items in stacks and +can be defined completely by their stack effects. This means they +can be auto-compiled.

      +
      +
      joy.library.zip_(stack, expression, dictionary)[source]
      diff --git a/docs/sphinx_docs/_build/html/notebooks/Derivatives_of_Regular_Expressions.html b/docs/sphinx_docs/_build/html/notebooks/Derivatives_of_Regular_Expressions.html index 241cd93..4e249e6 100644 --- a/docs/sphinx_docs/_build/html/notebooks/Derivatives_of_Regular_Expressions.html +++ b/docs/sphinx_docs/_build/html/notebooks/Derivatives_of_Regular_Expressions.html @@ -498,8 +498,9 @@ machine transition table.

      Says, “Three or more 1’s and not ending in 01 nor composed of all 1’s.”

      -
      -State Machine Diagram
      +
      +omg.svg

      omg.svg

      +

      Start at a and follow the transition arrows according to their labels. Accepting states have a double outline. (Graphic generated with Dot from Graphviz.) You’ll see that only diff --git a/docs/sphinx_docs/_build/html/objects.inv b/docs/sphinx_docs/_build/html/objects.inv index aa7fd30..fe60c2a 100644 Binary files a/docs/sphinx_docs/_build/html/objects.inv and b/docs/sphinx_docs/_build/html/objects.inv differ diff --git a/docs/sphinx_docs/_build/html/parser.html b/docs/sphinx_docs/_build/html/parser.html index c0cc06b..2565cb2 100644 --- a/docs/sphinx_docs/_build/html/parser.html +++ b/docs/sphinx_docs/_build/html/parser.html @@ -43,10 +43,14 @@ expression as well as a single Symbol class and a single Exception type.

      by the fact that they are not Symbol objects.

      A crude grammar:

      joy = term*
      -term = int | float | string | '[' joy ']' | function
      +term = int | float | string | '[' joy ']' | symbol
       
      -

      A Joy expression is a sequence of zero or more terms

      +

      A Joy expression is a sequence of zero or more terms. A term is a +literal value (integer, float, string, or Joy expression) or a function +symbol. Function symbols are unquoted strings and cannot contain square +brackets. Terms must be separated by blanks, which can be omitted +around square brackets.

      exception joy.parser.ParseError[source]
      diff --git a/docs/sphinx_docs/_build/html/py-modindex.html b/docs/sphinx_docs/_build/html/py-modindex.html index 31994b5..9a0c6f5 100644 --- a/docs/sphinx_docs/_build/html/py-modindex.html +++ b/docs/sphinx_docs/_build/html/py-modindex.html @@ -70,11 +70,6 @@
      - - -
          joy.utils.generated_library
          - joy.utils.polytypes -
          diff --git a/docs/sphinx_docs/_build/html/searchindex.js b/docs/sphinx_docs/_build/html/searchindex.js index 6c5fa7d..3de9c52 100644 --- a/docs/sphinx_docs/_build/html/searchindex.js +++ b/docs/sphinx_docs/_build/html/searchindex.js @@ -1 +1 @@ -Search.setIndex({docnames:["index","joy","lib","library","notebooks/Categorical","notebooks/Derivatives_of_Regular_Expressions","notebooks/Developing","notebooks/Generator_Programs","notebooks/Intro","notebooks/Newton-Raphson","notebooks/NoUpdates","notebooks/Ordered_Binary_Trees","notebooks/Quadratic","notebooks/Recursion_Combinators","notebooks/Replacing","notebooks/The_Four_Operations","notebooks/Treestep","notebooks/TypeChecking","notebooks/Types","notebooks/Zipper","notebooks/index","parser","pretty","stack","types"],envversion:52,filenames:["index.rst","joy.rst","lib.rst","library.rst","notebooks/Categorical.rst","notebooks/Derivatives_of_Regular_Expressions.rst","notebooks/Developing.rst","notebooks/Generator_Programs.rst","notebooks/Intro.rst","notebooks/Newton-Raphson.rst","notebooks/NoUpdates.rst","notebooks/Ordered_Binary_Trees.rst","notebooks/Quadratic.rst","notebooks/Recursion_Combinators.rst","notebooks/Replacing.rst","notebooks/The_Four_Operations.rst","notebooks/Treestep.rst","notebooks/TypeChecking.rst","notebooks/Types.rst","notebooks/Zipper.rst","notebooks/index.rst","parser.rst","pretty.rst","stack.rst","types.rst"],objects:{"joy.joy":{joy:[1,1,1,""],repl:[1,1,1,""],run:[1,1,1,""]},"joy.library":{"void":[3,1,1,""],BinaryBuiltinWrapper:[3,1,1,""],DefinitionWrapper:[3,2,1,""],FunctionWrapper:[3,1,1,""],SimpleFunctionWrapper:[3,1,1,""],UnaryBuiltinWrapper:[3,1,1,""],add_aliases:[3,1,1,""],app1:[3,1,1,""],app2:[3,1,1,""],app3:[3,1,1,""],b:[3,1,1,""],branch:[3,1,1,""],choice:[3,1,1,""],clear:[3,1,1,""],cmp_:[3,1,1,""],concat_:[3,1,1,""],cond:[3,1,1,""],dip:[3,1,1,""],dipd:[3,1,1,""],dipdd:[3,1,1,""],divmod_:[3,1,1,""],drop:[3,1,1,""],dupdip:[3,1,1,""],floor:[3,1,1,""],genrec:[3,1,1,""],getitem:[3,1,1,""],help_:[3,1,1,""],i:[3,1,1,""],id_:[3,1,1,""],infra:[3,1,1,""],initialize:[3,1,1,""],inscribe:[3,1,1,""],loop:[3,1,1,""],map_:[3,1,1,""],max_:[3,1,1,""],min_:[3,1,1,""],parse:[3,1,1,""],pm:[3,1,1,""],pred:[3,1,1,""],remove:[3,1,1,""],reverse:[3,1,1,""],select:[3,1,1,""],sharing:[3,1,1,""],shunt:[3,1,1,""],sort_:[3,1,1,""],sqrt:[3,1,1,""],step:[3,1,1,""],succ:[3,1,1,""],sum_:[3,1,1,""],take:[3,1,1,""],times:[3,1,1,""],unique:[3,1,1,""],unstack:[3,1,1,""],warranty:[3,1,1,""],words:[3,1,1,""],x:[3,1,1,""],zip_:[3,1,1,""]},"joy.library.DefinitionWrapper":{add_def:[3,3,1,""],add_definitions:[3,3,1,""],parse_definition:[3,3,1,""]},"joy.parser":{ParseError:[21,4,1,""],Symbol:[21,2,1,""],text_to_expression:[21,1,1,""]},"joy.utils":{generated_library:[3,0,0,"-"],polytypes:[24,0,0,"-"],pretty_print:[22,0,0,"-"],stack:[23,0,0,"-"],types:[24,0,0,"-"]},"joy.utils.generated_library":{ccons:[3,1,1,""],cons:[3,1,1,""],dup:[3,1,1,""],dupd:[3,1,1,""],dupdd:[3,1,1,""],first:[3,1,1,""],first_two:[3,1,1,""],fourth:[3,1,1,""],over:[3,1,1,""],pop:[3,1,1,""],popd:[3,1,1,""],popdd:[3,1,1,""],popop:[3,1,1,""],popopd:[3,1,1,""],popopdd:[3,1,1,""],rest:[3,1,1,""],rolldown:[3,1,1,""],rollup:[3,1,1,""],rrest:[3,1,1,""],second:[3,1,1,""],stack:[3,1,1,""],stuncons:[3,1,1,""],stununcons:[3,1,1,""],swaack:[3,1,1,""],swap:[3,1,1,""],swons:[3,1,1,""],third:[3,1,1,""],tuck:[3,1,1,""],uncons:[3,1,1,""],unit:[3,1,1,""],unswons:[3,1,1,""]},"joy.utils.polytypes":{CombinatorJoyType:[24,2,1,""],FUNCTIONS:[24,5,1,""],FunctionJoyType:[24,2,1,""],IntJoyType:[24,2,1,""],KleeneStar:[24,2,1,""],SymbolJoyType:[24,2,1,""],compose:[24,1,1,""],defs:[24,1,1,""],infer:[24,1,1,""],meta_compose:[24,1,1,""],type_check:[24,1,1,""]},"joy.utils.polytypes.KleeneStar":{kind:[24,6,1,""]},"joy.utils.pretty_print":{TracePrinter:[22,2,1,""]},"joy.utils.pretty_print.TracePrinter":{go:[22,7,1,""],viewer:[22,7,1,""]},"joy.utils.stack":{concat:[23,1,1,""],expression_to_string:[23,1,1,""],iter_stack:[23,1,1,""],list_to_stack:[23,1,1,""],pick:[23,1,1,""],stack_to_string:[23,1,1,""]},"joy.utils.types":{AnyJoyType:[24,2,1,""],BooleanJoyType:[24,2,1,""],FloatJoyType:[24,2,1,""],IntJoyType:[24,2,1,""],JoyTypeError:[24,4,1,""],NumberJoyType:[24,2,1,""],StackJoyType:[24,2,1,""],compilable:[24,1,1,""],compile_:[24,1,1,""],compose:[24,1,1,""],defs:[24,1,1,""],delabel:[24,1,1,""],doc_from_stack_effect:[24,1,1,""],reify:[24,1,1,""],relabel:[24,1,1,""],unify:[24,1,1,""]},"joy.utils.types.BooleanJoyType":{accept:[24,6,1,""]},"joy.utils.types.FloatJoyType":{accept:[24,6,1,""]},"joy.utils.types.IntJoyType":{accept:[24,6,1,""]},"joy.utils.types.StackJoyType":{accept:[24,6,1,""]},joy:{joy:[1,0,0,"-"],library:[3,0,0,"-"],parser:[21,0,0,"-"]}},objnames:{"0":["py","module","Python module"],"1":["py","function","Python function"],"2":["py","class","Python class"],"3":["py","classmethod","Python class method"],"4":["py","exception","Python exception"],"5":["py","data","Python data"],"6":["py","attribute","Python attribute"],"7":["py","method","Python method"]},objtypes:{"0":"py:module","1":"py:function","2":"py:class","3":"py:classmethod","4":"py:exception","5":"py:data","6":"py:attribute","7":"py:method"},terms:{"05s":5,"0b11100111011011":6,"23rd":18,"5bkei":11,"\u03b4":5,"\u03b5":9,"abstract":[8,11],"boolean":[2,3,8,11,15],"break":[5,8,18],"byte":[5,6],"case":[2,3,13,15,16,18,23],"char":5,"class":[3,5,8,18,21,22,23,24],"default":[3,7,11,23],"export":[3,21],"final":[2,11,13],"float":[3,8,18,19,21,24],"function":[0,1,4,6,7,10,12,17,19,20,21,22,23,24],"g\u00e9rard":19,"goto":5,"import":[2,5,6,7,9,11,12,13,14,16,17,18,19],"int":[5,7,8,13,18,19,21,23,24],"long":[11,18,20],"new":[2,3,5,7,8,10,13,14,18,24],"p\u00f6ial":20,"p\u00f6ial06typingtool":18,"public":10,"return":[1,3,5,6,8,11,13,14,15,16,18,21,22,23,24],"static":[2,10],"super":18,"switch":[2,18],"throw":[11,24],"true":[2,3,5,6,13,15,18,24],"try":[7,9,12,13,16,17,18,20],"void":[0,3],"while":[3,5,8,11,18,21,23],AND:[5,18],Adding:[8,14,20],And:[5,6,7,9,11,13,15,18,19,23],But:[0,4,6,7,8,11,14,18],CPS:8,For:[2,3,11,13,14,18,20,23,24],Its:3,NOT:5,Not:18,One:[2,8,15,18,20],REs:5,TOS:[2,3],That:[6,11],The:[0,1,2,3,4,5,7,9,10,12,19,20,21,23,24],Then:[2,3,11,12,13,18],There:[5,12,13,15,16,18,23],These:[15,18,20,23,24],Use:[3,9,13],Used:15,Using:[0,9,11,20],With:[9,13,18,20,24],_1000:18,__add__:18,__builtin__:24,__call__:5,__class__:18,__eq__:18,__ge__:18,__hash__:18,__init__:[5,18],__main__:18,__radd__:18,__repr__:18,__str__:22,_and:5,_compaction_rul:5,_con:5,_dictionari:18,_ge:18,_infer:18,_interpret:18,_log:18,_log_it:18,_names_for:18,_or:5,_templat:5,_to_str:18,_tree_add_:11,_tree_add_e:[11,24],_tree_add_p:11,_tree_add_r:11,_tree_add_t:11,_tree_delete_:11,_tree_delete_clear_stuff:[11,24],_tree_delete_del:11,_tree_delete_r0:[11,24],_tree_delete_r1:11,_tree_delete_rightmost:11,_tree_delete_w:11,_tree_get_:[11,24],_tree_get_p:11,_tree_get_r:11,_tree_get_t:11,_tree_iter_order_curr:11,_tree_iter_order_left:11,_tree_iter_order_r:11,_tree_iter_order_right:11,_tree_t:11,_treestep_0:16,_treestep_1:16,_uniqu:18,_within_b:9,_within_p:9,_within_r:9,a10001:18,a10002:18,a10003:18,a10004:18,abbrevi:16,abl:[5,15,18,24],about:[0,8,11,15,18,19,23,24],abov:[0,5,6,9,11,13,15,18],abs:9,absolut:8,accept:[1,2,3,5,6,7,8,11,12,14,15,16,18,19,24],accord:5,accordingli:[11,15],accumul:6,act:[5,24],action:[0,8,14,18,19,20],actual:[2,6,8,11,15,18],adapt:20,add:[3,5,6,7,8,14,18,22,24],add_alias:3,add_def:3,add_definit:[3,11,16],added:[4,11],adding:[10,18],addit:[0,2,3,6,8,13,14,16],address:20,adjust:[11,24],advantag:18,affect:15,after:[5,6,7,8,13,15,18,24],afterward:8,again:[2,3,6,8,11,13,18,24],against:[18,24],aggreg:19,ahead:18,aka:[5,8,19,24],albrecht:0,algorithm:[5,8,18],alia:[3,24],alias:[3,8],align:[8,22],all:[3,5,6,7,8,11,13,14,15,16,18,22,24],alloc:18,allow:[10,11,15],almost:11,along:[5,8,13,18,24],alphabet:[3,20],alreadi:[5,9,14,18,19],also:[0,5,6,8,11,15,18,23,24],alter:[5,18],altern:[4,18,24],although:[4,11],altogeth:7,alwai:[6,10,13,15],amend:15,among:18,amort:11,analysi:[4,20],anamorph:[8,20],ani:[4,5,6,8,10,11,15,18,19,21,24],annual:8,anonym:11,anoth:[5,11,15,18,23,24],anyhow:[15,18],anyjoytyp:[18,24],anymor:18,anystarjoytyp:18,anyth:[2,3,5,8,18,24],apart:18,api:10,app1:3,app2:[3,8,12,13,14,15],app3:[3,15],app:8,appear:[2,4,5,6,11,24],append:18,appendix:20,appli:[2,3,6,7,11,13,18,24],applic:7,approach:6,appropri:5,approxim:20,archiv:0,aren:19,arg:[2,3],argument:[2,3,8,9,12,13,20,22,23],arithmet:2,ariti:[2,15],around:[6,18,23],arrang:16,arriv:[7,16],arrow:5,articl:[0,4,7,13],ascii:5,ascii_lowercas:5,ask:[4,7,18],aspect:0,assembl:5,assert:[5,18],assign:[15,23],associ:11,assum:9,asterisk:16,asterix:[18,24],asyncron:15,attack:8,attempt:[0,1,18],attribut:3,attributeerror:18,author:18,auto:[0,18,24],automat:[4,15,18,24],auxiliari:[5,16],avail:[0,18,24],averag:[8,14],avoid:[11,24],awai:[11,18],awar:2,awkward:[11,13,18],azur:20,back:[11,18],backtrack:24,backward:[10,11,12,16],bad:18,bag:8,banana:13,bar:15,barb:13,base:[0,2,3,10,13,16,18],basic:[1,2,3,8,11],basicconfig:[17,18],becaas:5,becaus:[2,3,5,8,11,15,16,18,19,23,24],becom:[11,16,23],becuas:18,been:[5,9,10,11,18,19],befor:[5,7,8,11],begin:[11,16],behavior:[10,16,24],behaviour:[0,1,18,24],behind:15,being:[0,15,24],below:[2,3,5,6,7,11,18,19],bespok:8,best:0,better:[6,11,13,18],between:[0,6,24],beyond:7,biannual:8,bin:5,binari:[0,7,8,20],binary_search_tre:11,binarybuiltinwrapp:3,bind:8,bingo:19,bit:[5,6,7,11,18],bliss:[0,20],block:6,bodi:[2,5,8,11,15],body_text:3,booktitl:18,bool:[13,18,24],booleanjoytyp:24,borrow:[8,18],both:[2,6,8,12,13,14,15,18,23],bottom:7,bounce_to:5,bracket:[8,18,21],branch:[3,5,6,7,13,18,20,24],branch_fals:18,branch_tru:18,breakpoint:8,bring:[6,8,18],bruijn:18,brutal:15,brzozowski:[18,20],brzozowskian:5,btree:[11,16],buck:11,bug:[0,8],build:[7,8,12,13,19,23],built:[12,18],bundl:[2,3,13],burgeon:8,calculu:4,call:[2,5,8,10,11,13,15,18,22,23],caller:[11,18],can:[0,2,3,4,5,6,7,8,9,10,12,13,14,15,16,18,19,20,23,24],cancel:15,cannot:[17,18],captur:[8,24],card:8,care:[6,23],carefulli:19,carri:[7,11,24],cartesian:4,catamorph:20,categor:[0,20],categori:[4,15],ccc:4,ccon:[3,11,17,18,24],cell:[13,18],certain:[8,23],certainli:11,chain:[3,15],chang:[2,10,11,18,19],charact:[5,19],chat:8,chatter:[0,18],check:[0,7,9,18,20,24],child:16,choic:[3,13],choos:10,chop:12,chose:5,cinf:11,circl:5,circuit:4,cite_not:11,classmethod:3,claus:[3,18],clean:18,clear:[3,6,8,24],clear_stuff:11,cleav:[8,12,14],close:[0,1,4],clunki:[6,18],clv:15,cmp:[3,16,20],cmp_:3,code:[0,1,4,5,12,13,15,18,20,24],codireco:[7,9],collaps:13,collect:[4,5,7,8,18],collis:24,combin:[0,3,6,7,8,9,12,15,16,19,20,24],combinatorjoytyp:[18,24],come:[8,11,18],command:[8,11,18],comment:[15,24],common:[2,6,15],compar:[3,4,5,18],comparison:[0,11],compat:15,compel:4,compil:[2,4,5,8,11,14,15,20,24],compile_:24,complement:5,complet:4,complex:[3,15,18,19,24],complic:18,compos:[5,24],composit:[18,24],compostit:18,compound:11,comput:[2,4,5,6,8,12,15,18,24],con:[3,5,6,7,8,9,11,12,13,15,16,19,23,24],conal:[4,15],concat:[3,7,8,15,16,18,23],concat_:[3,24],concaten:[0,5],concatin:[0,3,5,23],concern:15,conclus:20,concurr:2,cond:[3,11],condit:[3,8],confer:18,conflict:[11,18,24],consecut:20,consid:[5,6,7,11,13,16,18,19],consist:[2,7,8,15,16],constant:11,constitu:13,construct:[15,18],consum:[15,18],contain:[0,2,3,5,7,8,13,18],content:18,context:2,conting:11,continu:[0,5,13,18,19],control:8,conveni:[4,15,18],convent:15,convers:18,convert:[13,14,16,18,21,23],cool:11,copi:[2,3,6,11,13,15,16,17,20],copyright:8,correspond:[4,15],could:[2,4,5,6,8,10,11,15,18,19],couldn:15,count:[3,18],counter:[6,18],coupl:16,cours:[6,11,18],cover:18,cpu:15,crack:11,crash:11,creat:[0,2,3,6,9,11,15,18],creativ:18,crude:[11,18,21,24],cruft:18,curent:24,current:[2,3,8,13,15,16,18,19,22,24],curri:5,custom:10,cycl:[6,7],cython:8,d010101:5,d0101:5,d01:5,d10:5,d_compact:5,dai:8,data:[2,3,5,13],datastructur:[0,2,13,18,20,21,23],datatyp:23,ddididi:19,deal:[0,5,11,15],dealt:18,debugg:18,decid:11,declar:18,decor:3,decoupl:13,decrement:3,deduc:[6,18],deeper:0,deepli:4,def:[3,5,8,13,14,18,23,24],defaultdict:[5,18],defi:3,defin:[2,3,4,5,6,7,8,9,10,12,13,14,15,18,19,20],definit:[0,2,3,6,7,8,10,11,13,16,18,20,24],definitionwrapp:[3,11,13,16],defint:15,del:17,delabel:24,deleg:8,delet:20,deliber:18,demo:18,demonstr:4,depend:[3,11,13,15],deposit:16,depth:[18,24],dequot:13,der:11,deriv:[2,3,6,8,9,11,18,20],derv:5,describ:[3,4,5,11,13,15,16,18,21,24],descript:[6,8],descriptor:18,design:[2,3,11,15,20],desir:[8,16],destin:5,destruct:11,detail:[8,11,18],detect:[5,7,11,13,18],determin:20,develop:[0,7,8,18,20],diagram:6,dialect:1,dict:[1,3,5,18,24],dictionari:[0,1,3,8,18,20],did:18,differ:[0,4,6,9,11,12,13,15,23],differenti:4,difficult:18,difficulti:15,dig:[11,19],digit:6,digraph:5,dinfrirst:[8,18,24],dip:[3,6,7,8,9,11,12,13,14,15,16,18,20,24],dipd:[3,7,8,11,12,13,15,18,19,24],dipdd:[3,11,24],direco:20,direct:8,directli:[6,15,16,18,23],disappear:[2,5,18,24],discard:[3,7,9,11,13],disciplin:11,disenstacken:8,disk:8,displac:2,displai:18,distiguish:18,distribut:15,ditch:11,div:[3,8,18,24],dive:16,divis:11,divmod:[3,24],divmod_:[3,18],doc:[2,3,8,18,24],doc_from_stack_effect:[17,24],docstr:[18,24],document:[18,20,21,23],doe:[0,1,4,5,7,8,14,15,18,20,22,24],doesn:[6,10,11,15,16,18,23],doing:[4,6,8,15,18,19],domain:[4,18],don:[5,6,8,11,18,24],done:[2,6,8,10,18],dooooc:18,door:8,dot:[5,22],doubl:[5,6,8,18],doublecircl:5,down:[2,5,9,13,19,24],down_to_zero:8,dozen:8,draft:[4,10],dream:8,drive:[7,9],driven:6,driver:[5,7],drop:[3,11],dudipd:8,due:18,dup:[3,6,7,8,9,11,12,13,15,17,19,23,24],dupd:[3,18,24],dupdd:[3,24],dupdip:[3,6,11,12,13,24],duplic:[3,11,13],durat:2,dure:[2,13],each:[2,3,4,5,6,8,13,14,15,16,18,22,24],easi:[0,11,16,18,19],easier:[3,11,15],easili:4,eat:5,edit:20,effect:[2,3,5,8,15,19,20,24],effici:[7,14,19],efg:18,either:[1,2,3,5,11,13,18],elabor:18,eleg:[0,5,8,11,15,20],element:2,elif:18,elimin:[5,18],elliott:[4,15],els:[2,3,5,13,15,18],else_:18,embed:[4,11,19],emit:18,empti:[3,5,8,16,18,23,24],encapsul:8,enclos:8,encod:7,encount:18,end:[5,6,11,13,16,18,23],endless:7,enforc:[2,8],engend:8,enough:[5,8,13,22,24],enstacken:[7,8,18],enter:[8,24],enter_guard:18,entir:23,entri:[3,19,22],enumer:18,epsilon:9,equal:[6,16,23],equat:[8,9],equival:15,ergo:[5,11],err:[11,17],error:[8,18,21],essai:0,establish:18,etc:[3,16,18,19,21],euler:20,euro:18,eval:[0,18],evalu:[1,2,3,8,9,11,12,13,14,15,16,18],event:15,eventu:[15,18],ever:18,everi:[7,15],everybodi:15,everyth:[3,5,11,12,15,18],evolv:10,examin:13,exampl:[0,3,5,6,18,20,21,23,24],exce:7,except:[5,8,11,17,18,21,24],execut:[0,1,2,3,8,13,14,15,16,18,19,23,24],exend:18,exercis:[5,11],exist:[4,11,18],expand:11,expect:[2,3,15,16,18,23,24],experi:[8,16],explain:18,explan:8,explor:[8,18],express:[0,1,2,3,4,11,13,14,18,19,20,22,23],expression_to_str:[18,23],extend:18,extra:[6,7],extract:[11,12,20],extrem:8,extrememli:8,f_g:18,f_in:18,f_out:18,f_python:18,facet:0,facil:8,fact:21,factor:[2,6,8,11,18],factori:20,fail:[2,3,11,20,21,24],fairli:18,fake:5,fall:18,fals:[2,3,5,6,13,15,18,24],falsei:18,far:[9,11,13,18,24],fascin:0,favorit:15,fear:[11,18],few:[6,8,9,12,15,18],fewer:[3,8],fg_in:18,fg_out:18,fib:7,fib_gen:7,fibonacci:20,figur:[2,3,11,13,18],filter:11,fin:6,find:[2,3,5,6,7,15,16,18,20],finder:9,fine:[0,5,6,11,18,24],finite_state_machin:5,first:[3,5,7,8,9,11,12,13,14,16,19,20,24],first_two:[3,11,24],fit:[6,8],five:[6,8,20],fix:[2,3,5,13,18,24],fixm:[5,18],flag:[15,18],flatten:[8,16,18],flesh:5,flexibl:20,floatjoytyp:[18,24],floatstarjoytyp:18,floor:3,floordiv:[6,24],flow:8,follow:[0,2,3,5,8,10,13,15,16,18,19,24],foo:[8,10,11,15,18],foo_ii:10,fork:15,form:[2,3,4,5,6,7,13,16,18,23],forman:8,format:[17,18,20,22],formula:[0,6,20],forth:[8,18],forum:0,forward:18,found:8,four:[0,2,3,6,7,8,11,20],fourteen:6,fourth:[2,3,11,13,24],fractal:8,fraction0:8,fraction:[2,8],frame:13,framework:8,free:[4,8,11],freeli:2,from:[0,1,2,3,5,6,7,8,9,11,12,13,14,15,16,17,18,19,20,23],from_:5,front:[2,3,13],frozenset:5,fulin:15,full:6,fun:[5,20],func:18,functionjoytyp:[18,24],functionwrapp:3,functool:5,fundament:[0,20],funtion:11,further:[9,18,20],futur:15,g_in:18,g_out:18,garbag:8,gari:11,gcd:8,gener:[0,2,4,13,15,18,20,23,24],generated_librari:3,genrec:[3,8,11,13,15,16,18],geometr:6,get:[2,4,5,6,7,8,12,13,18,20],getch:5,getitem:3,getrecursionlimit:23,getsourc:8,ghc:4,give:[4,6,11,13,16,18,23],given:[2,3,6,7,9,11,13,15,18,19,20],global:[17,18],glue:8,goe:24,going:[5,11,12,15,16,18,19],good:[6,11,18],grab:18,grammar:21,grand:8,graph:15,graphic:5,graphviz:5,great:[0,8,18,20],greater:23,grind:18,group:0,grow:5,gsra:9,guard:[11,18,24],had:[5,6,19],haiku:8,half:[6,18,19],hallmark:15,hand:[5,8,14,18,20],handi:[9,18],handl:[11,18,23,24],happen:[8,18],happi:5,hard:[5,18,19],hardwar:4,has:[0,2,5,7,8,9,10,11,13,15,18,19,23],hasattr:18,hash:18,haskel:4,have:[2,3,5,6,7,8,9,10,13,14,15,18,19,20,23,24],haven:24,head:23,heh:18,help:[8,11,13,18],help_:3,helper:[3,5],herd:8,here:[5,6,7,11,16,18,19,24],hide:11,hierarchi:18,higher:[5,8,11,18],highli:8,hij:5,histori:[18,22,24],hit:5,hmm:[5,11],hoist:3,hold:[6,18],hood:11,hope:[0,6,8,20],hopefulli:13,host:20,how:[0,4,5,9,11,13,18,19,20],howev:[13,14,15,18],html:[2,3,7,12,13,20],http:11,huet:19,huge:11,hugh:[9,16],human:8,hybrid:24,hylomorph:20,hypothet:2,id_:3,idea:[4,6,8,18],ident:[3,5,13,18,24],if_not_empti:11,ift:[3,11,13,16,18,24],ignor:[3,11,18],iii:20,illustr:[5,13],imagin:[5,15,19],imap:18,imit:[5,16],immedi:[5,13],immut:[5,8,11],imper:13,implement:[0,1,2,3,4,8,10,11,13,14,15,20,24],implementaion:15,implicit:8,improv:18,includ:[4,11,15,16,18,24],inclus:6,incom:23,incompat:10,incorpor:12,increas:6,increment:[3,4,6,10,15],indetermin:24,index:[0,8,18,23],indexerror:23,indic:[15,16,18,24],ineffici:18,infer:[0,17],inferenc:24,info:[17,18],inform:[3,5,18,24],infra:[3,7,8,11,12,14,15,16,18,20,24],infrastructur:3,initi:[2,3,5,8,9,11,18],inlin:11,inner:18,inproceed:18,input:[1,9,15,17,18,24],input_:5,inscrib:3,insert:18,insight:13,inspect:8,inspect_stack:18,instal:0,instanc:[18,24],instanti:[4,22],instead:[5,6,7,11,13,18,19,23,24],instruct:5,integ:[2,3,8,13,16,18],integr:3,intend:[0,8],interact:[8,20],interest:[0,6,11,18,20],interfer:15,interlud:20,intermedi:13,intern:[0,18,22,23],interpret:[0,4,10,14,21,22,24],interrupt:8,intersect:5,interspers:15,interv:[4,6],intjoytyp:[18,24],introduc:[10,24],introduct:0,intstarjoytyp:18,intuit:18,invalid:24,invari:3,invent:18,involv:18,ipf:8,isinst:[5,18],isn:[5,11,19],issubclass:18,item:[2,3,8,11,13,15,16,18,20,23],iter:[1,3,5,8,13,15,16,18,20,23],iter_stack:[14,23],iteritem:[5,18],itertool:[5,18],its:[0,2,3,4,6,8,11,13,15,16,18,23],itself:[0,2,8,11,15,18,24],j05cmp:[2,3,13],jaanu:18,jmp:5,job:[15,20],john:[9,16],joi:[2,4,10,11,12,14,15,17],join:[5,18],joypi:[8,19],joytypeerror:[17,24],jump:5,jump_from:5,junk:18,jupyt:20,just:[0,2,3,5,7,8,10,11,13,15,16,18,19],juxtaposit:15,keep:[5,11,12,15,18,19],kei:[5,16,20],kevin:0,key_n:11,keyerror:[5,11,18],kind:[2,4,8,11,13,16,18,24],kinda:18,kleen:[16,18,24],kleenestar:[18,24],kleffner:18,know:[6,11,18],knowledg:18,known:[4,15],kstar:5,l_kei:11,l_left:11,l_right:11,l_valu:11,label:[5,18],lambda:[4,5,18],languag:[4,5,8,10,11,14,18],larg:[5,18],larger:[20,23],largest:3,last:[6,11,13,18],lastli:7,later:[5,8,16,18],law:2,lazi:18,lazili:9,lcm:6,lead:[5,8,18,24],leaf:11,lean:8,learn:0,least:[2,6,13,18,23],least_fract:8,leav:[6,15],left:[5,8,12,13,15,16,18,19,22,23,24],leftov:13,legend:5,len:[5,18],length:[3,6,23],lens:13,less:[6,7,8,13,18,23],let:[7,9,11,12,13,16,18,19,20],letter:18,level:[4,5,11,17,18],librari:[0,5,14],like:[2,3,5,6,8,15,16,18,20,21,24],limit:[18,24],line:[3,8,11,12,18,22,24],linear:23,link:[0,5,18],linux:0,list:[0,3,5,6,8,9,11,13,15,16,18,19,22,24],list_to_stack:[18,23],liter:[1,11,16,18,19,21],literatur:18,littl:[5,7,11,15,18,20],live:20,lkei:16,load:[6,8],local:18,locat:2,locu:22,log:[17,18],log_2:11,logic:[0,6,20],longer:[11,18],look:[5,7,8,9,11,12,15,18],lookup:8,loop:[0,1,3,5,6,18,20,24],lose:18,lot:[5,8,11,18,19],love:6,low:[4,5],lower:6,lowercas:[5,18],lowest:11,lshift:24,machin:[0,20],machineri:[11,18,24],macro:8,made:[0,8,15,18,19],magic:18,mai:[2,13,15],mail:0,main:[0,3,8,12,15,18,19],mainloop:10,maintain:19,major:10,make:[2,3,4,6,8,11,13,14,15,16,18,19,20],make_gener:9,make_graph:5,manfr:[0,2,3,4,13],mani:[0,5,8,18],manipul:18,manner:12,map:[1,3,5,6,8,10,13,16,18],map_:3,marker:8,mask:[6,7],match:[0,1,18,20],materi:0,math:[0,8,9,11,12,18],mathemat:8,matter:[6,9,11,16],max_:3,maximum:3,mayb:[11,18],mean:[4,6,8,9,11,13,16,18,23,24],meant:[8,11,13,16],mem:5,member:[2,3,13],memo:5,mental:8,mention:2,mercuri:0,mess:18,messag:[17,18],meta:[8,11,14],meta_compos:[18,24],method:[0,3,8,18,20,22],midpoint:6,might:[4,5,7,11,18],mike:11,million:7,min_:3,mind:18,minimum:3,minor:11,minu:3,mirror:0,miscellan:0,mismatch:18,mix:[8,18],mod:3,mode:18,model:[4,8],modern:0,modif:[7,18],modifi:[8,11,19],modul:[0,1,3,8,18,21],modulu:[8,24],moment:18,month:8,more:[0,3,4,5,6,7,8,9,13,14,15,16,18,21,23,24],most:[5,18,24],mostli:0,move:[5,11],movement:2,much:[5,6,7,11,13,18],muck:11,mul:[8,12,17,19,22,24],multi:3,multipl:[20,24],must:[2,3,6,10,13,15,16,18],myself:18,n10001:18,n10002:18,n10003:18,n1001:18,n1002:18,n1003:18,name:[1,3,5,8,10,11,13,18,19,20,21,23,24],narr:18,natur:[5,6,7,11,18],navig:19,nearli:18,neat:11,neato:18,necessarili:18,need:[2,3,6,7,9,10,11,13,15,18],neg:[3,12,24],neither:[15,18],ness:5,nest:[3,8,11,19],network:8,never:[5,10,13],new_def:18,new_f:18,new_fo:18,new_kei:11,new_valu:11,newton:[0,20],next:[5,6,15,16,18,24],nice:[0,5,13,23],niether:2,node:[5,16,20],node_kei:11,node_valu:11,non:[5,16,18,24],none:[1,3,18,24],nope:16,nor:5,normal:15,notat:[8,11],note:[2,5,6,9,11,13,15,18,23],notebook:[6,7,8,18,19,20],notebook_preambl:[2,6,7,9,11,12,13,14,16,18,19],noth:[2,11,15],notic:6,now:[5,6,7,8,13,14,16,18,20],nth:[3,23],nullari:[8,11,15,18,24],number:[1,2,3,6,7,9,15,23,24],numberjoytyp:[18,24],numberstarjoytyp:18,numer:18,object:[5,18,21],observ:6,obviou:7,obvious:18,occur:11,odd:[6,7],off:[2,3,6,7,12,18,19],often:[5,15],old:[2,14],old_k:11,old_kei:11,old_valu:11,omit:[13,18],onc:[3,5,10,11],one:[2,3,5,6,7,11,13,15,16,18,22,23,24],ones:[5,7,18],onli:[2,3,5,6,11,13,15,18,19,23,24],onto:[1,2,3,8,13,23],open:[8,18],oper:[0,3,5,8,11,13,20,23],oppos:18,optim:11,option:[1,8,11,18,23],orchestr:15,order:[0,2,3,8,13,15,17,18,20,23],org:[0,11],origin:[0,1,2,3,11,19],other:[0,2,3,4,5,8,11,13,16,18,23,24],otherwis:[3,5,6,7,11,16,18,24],our:[5,6,7,8,9,13,16,18],out:[2,3,4,6,7,8,9,11,12,13,15,18,19,20],outcom:16,outlin:5,output:[5,9,13,15,17,18,24],outsid:4,over:[3,4,6,7,8,9,11,12,15,16,18,20,24],overhaul:18,overview:18,own:[11,18],pack:23,packag:[0,8],page:[0,11,18,23],pair:[2,3,6,7,11,18],palidrom:6,palindrom:6,pam:8,paper:[4,8,13,15,19],paradigm:20,parallel:[2,20],paramet:[1,2,3,13,14,21,22,23],parameter:20,paramorph:13,parenthes:[11,23],pariti:7,pars:[0,3,5,8],parse_definit:3,parseerror:21,parser:[0,17,18],part:[2,3,9,13,16,20],partial:[5,18],particular:19,pass:[0,5,11,18,22,24],patch:5,path:[5,18,20],pattern:[5,6,15,16,20],pe1:[6,7],pe2:7,pearl:19,pend:[3,8,13,18,19,22],peopl:20,per:[8,16],perfectli:15,perform:[5,15,18],perhap:7,period:8,permit:[15,18,23],permut:18,persist:11,phase:2,phi:5,pick:[6,7,15,23],pickl:8,pictur:11,piec:13,pip:0,place:[3,6,8,18],plai:0,plu:3,plug:[7,13,16],point:[4,5,8,11,13,15],pointless:2,polytyp:[0,17,18],pool:15,pop:[3,5,6,7,8,11,13,14,16,17,23,24],popd:[3,8,9,11,14,15,18,24],popdd:[3,7,12,18,24],popop:[3,6,7,8,9,11,16,18,24],popopd:[3,24],popopdd:[3,24],posit:[3,6,8,13],possibilit:11,possibl:[11,16,18,20],post:8,poswrd:18,potenti:15,pow:24,power:[8,18],pprint:5,pragmat:6,preambl:9,preceed:15,precis:[0,1],pred:[3,18,24],predic:[2,3,5,7,13,15,24],prefix:[18,22],preliminari:5,present:18,preserv:[4,16],pretti:[9,11,12,15,16,18,22,23],pretty_print:0,previou:[8,15],prime:9,primit:[2,3,18,20],primrec:[3,7,8,9,13],print:[0,1,2,3,5,17,18,22,23,24],probabl:[7,8,11,18],problem:[8,18,20],proc_curr:11,proc_left:11,proc_right:11,proce:[6,24],process:[5,8,16,18,22],produc:[6,11,13,16,18],product:[5,7,8,17,18,24],program:[0,2,3,7,8,9,11,13,15,18,19,24],programm:[15,18],progress:15,project:20,prolog:18,promis:15,prompt:8,proper:[2,3,13,15,24],properti:0,provid:[0,3,4,8,15,18,24],pun:[0,8],punctuat:18,pure:[0,5],puriti:8,purpos:8,push:[2,3,8,13,19,23],pushback:8,put:[1,2,7,8,15,18,20,23],pypi:0,python:[0,2,3,5,11,13,15,19,20,21,23,24],quadrat:[0,20],queri:[11,16],query_kei:16,queu:13,quit:[0,1,16],quot:[0,3,7,8,11,12,13,15,16,18,19,22,24],quotat:[2,3,13],quotient:3,r_kei:11,r_left:11,r_right:11,r_valu:11,rais:[5,11,18,21,23],rang:[5,8,18],range_revers:13,range_to_zero:8,ranger:13,ranger_revers:13,rankdir:5,raphson:9,rather:[6,8,13,16],ratio:8,reach:[5,6,7,13],read:[0,1,6,7,11,18,19],readabl:14,reader:[5,11],readi:18,real:11,realiz:[4,11],rearrang:[2,11,18],reason:[6,8,15,18],rebuild:[16,19],rec1:[2,3,13],rec2:[2,3,13],recogn:21,recombin:15,record:[8,22],recur:[13,18],recurs:[0,2,3,5,7,8,9,15,18,20,23],recus:8,redefin:20,redistribut:[3,8],redo:5,reduc:[2,18],redund:23,refactor:[8,10],refer:[0,2],referenti:15,reflect:15,regard:15,regist:2,regular:[18,20,21],reifi:[17,24],reimplement:[15,20],relabel:24,relat:[5,18],releas:10,remain:[2,8,10,18],remaind:[3,9],rememb:5,remind:18,remov:[3,11,18,23],render:20,repeat:6,repeatedli:6,repetit:5,repl:[0,1],replac:[0,2,3,7,12,13,15,16,18,19,20,23],repositori:0,repr:[5,18],repres:[2,8,11,15,21,22,24],represent:[23,24],reprod:7,repurpos:18,requir:[15,18,23],res:18,research:18,resembl:8,resolut:15,resourc:15,respect:[5,6,15],rest:[3,6,7,8,11,13,19,20,23,24],rest_two:11,restor:2,result:[1,2,3,5,6,11,12,13,15,16,18,19],resum:8,retir:2,retri:8,reus:[11,18],revers:[3,6,7,13,18,19,20,23],revisit:18,rewrit:[3,8,18],rewritten:8,rid:11,right:[7,8,12,16,18,20,22,23,24],rightest:11,rightmost:6,rigor:15,risk:18,rkei:16,rob:18,roll:[3,9,11,16,24],roll_dn:18,rolldown:[3,17,18,24],rollup:[3,18,24],root:[3,9,12],round:18,row:5,rrest:[3,17,18,24],rshift:24,rule:[15,20],run:[0,1,3,6,8,9,11,12,13,15,16,18,19],runtim:15,runtimeerror:23,sai:[5,7,11,12,16,18],same:[2,4,6,11,15,18,23],sandwich:[2,3,13],save:[2,5,6,8],scan:3,scanner:[8,21],scenario:19,scope:[7,11],search:[0,11],sec:[18,24],second:[3,8,11,13,16,23,24],section:13,see:[0,5,7,8,9,10,12,13,14,18,19,22],seem:[0,6,8,16,18,24],seen:[18,19,24],select:3,self:[5,15,18],semant:[2,3,8,10,11,15,18],semi:8,send:8,sens:[0,2,6,18,19],separ:[8,15,18],seq:18,sequenc:[0,1,2,3,6,8,11,13,14,19,20,21,24],sequence_to_stack:18,seri:[6,7,11,19],ses:18,set:[2,3,5,13,18,20],seven:[6,7],sever:[0,4,8,13],shape:[5,15],share:[3,8],shelf:2,shew:5,shift:[6,7],shorter:20,shorthand:11,should:[2,3,5,6,11,13,15,18],shouldn:8,show:[4,15,18,19],shunt:[3,19],side:[5,11,17,18,24],signatur:24,signifi:[8,11],similar:[11,16,18],simon:8,simpl:[5,8,13,23,24],simplefunctionwrapp:[3,14,18],simpler:16,simplest:[18,20],simpli:4,simplifi:[6,11,19],sinc:[2,6,11,18],singl:[3,7,8,14,15,18,21,24],singleton:5,situ:11,situat:11,six:[6,7,8],sixti:[6,7],size:[5,8,20],skeptic:8,skip:18,slight:9,slightli:[11,13,18],smallest:3,smart:11,softwar:8,solei:2,solut:[6,7],solvabl:8,some:[2,3,5,7,8,11,13,15,16,18,20,23,24],somehow:[11,18],someth:[2,10,11,18],sometim:11,somewher:[11,20],sort:[3,5,11,15,18],sort_:3,sourc:[0,1,3,18,20,21,22,23,24],space:[6,22],span:6,spawn:18,special:[7,11,20],specif:[0,4],specifi:[11,15,24],speed:14,spell:[5,16],sphinx:[20,23,24],spirit:[0,1,16],split:[5,18,24],sqr:[8,9,12,19],sqrt:[3,9,18,24],squar:[3,9,18,21],stack:[0,1,3,6,7,9,11,12,13,14,15,16,17,19,20,21,22,24],stack_effect:18,stack_effect_com:18,stack_to_str:[17,23],stacki:18,stackjoytyp:[18,24],stackstarjoytyp:18,stage:16,stai:[0,1],stand:[4,5,24],standard:[8,11],star:[16,18,24],stare:11,start:[5,6,7,8,9,11,13,16,18,24],state:[8,20],state_nam:5,statement:[3,5],stdout:[17,18],step:[3,6,8,11,14,18,19,20],still:[5,11,18],stop:11,stopiter:5,storag:[6,11],store:[6,13,18],stori:13,str:[1,5,18,21,22,23],straightforward:[1,5,7,9,18,20],stream:[6,17,18],stretch:11,string:[1,2,3,8,18,19,20,21,22,23,24],stringi:5,structur:[8,15,16,18,19,20,23],stuck:5,studi:5,stuff:[11,18],stuncon:[3,24],stununcon:[3,24],style:[0,4,18],sub:[10,15,24],subclass:8,subject:[15,19],subsequ:15,subset:[18,24],substitut:[5,11,18,24],subtract:6,subtyp:20,succ:[3,18,24],succe:18,success:9,suck:18,suffic:18,suffici:11,suffix:18,suggest:[4,5,11],suitabl:[3,4,6],sum:[3,7,8,12,13,14,16,24],sum_:[3,18],summand:6,sumtre:16,suppli:[11,21],support:[8,18,22,23],sure:15,suspect:2,swaack:[3,12,14,18,19,24],swap:[3,6,7,8,9,11,13,14,15,16,17,19,24],swon:[3,7,8,13,16,18,19,24],swoncat:[7,8,9,13,16],swuncon:13,sym:5,symbol:[2,3,5,15,18,19,20,21],symboljoytyp:[18,24],symmetr:[6,11],symmetri:5,syntact:8,syntax:[8,23],sys:[17,18,23],system:[8,11,15],tabl:[5,18],tag:[5,18],tail:[11,18,20,23],take:[3,5,6,8,9,11,13,15,18,23],talk:[8,11,18,23],target:19,tast:4,tbd:8,tear:13,technic:2,techniqu:[4,19],technolog:2,temporari:19,ten:6,term:[1,2,5,8,9,13,15,18,20,21,23,24],termin:[2,3,5,13],ternari:8,test:[2,3,13],text:[0,1,3,18],text_to_express:[8,17,21],textual:8,than:[0,3,5,6,7,8,9,13,15,16,18,23,24],thei:[2,5,6,7,8,11,13,15,18,19,21,23,24],them:[2,3,5,6,7,11,13,15,18,19,20,24],themselv:[15,18,24],theori:[2,3,13,15],therefor:7,thi:[0,1,2,3,4,5,6,7,8,9,12,13,15,16,18,19,20,21,22,23,24],thing:[2,7,11,13,15,18,19,21,23,24],think:[2,6,8,11,13,15,16,18],third:[3,7,8,11,24],thirti:6,those:[2,3,5,11,13,18,20,24],though:[6,15],thought:[8,15],thousand:6,thread:[2,15],three:[2,3,5,6,8,11,12,16,18,20],through:[1,6,8,16,18,19,23,24],thun:[2,3,4,10,13,15],thunder:8,thunk:15,time:[3,5,6,8,9,11,13,15,18,19],titl:18,to_check:5,to_set:11,todai:8,todo:[8,21],togeth:[7,8,15,18,20],token:21,toler:20,too:[5,13,18],tool:[8,18],tooo:18,top:[2,3,8,13,18,22,23],total:6,tower:18,trace:[0,8,12,13,19,20,23],traceprint:22,track:[12,18,19],tracker:0,transform:4,transit:5,translat:[4,12,18],trap:5,travers:[0,20],treasur:0,treat:[0,2,3,13,18,20],treatment:7,tree:[0,8,20],treegrind:20,treestep:[0,20],tri:6,triangl:15,triangular_numb:13,trick:[6,18],tricki:18,trinari:24,trobe:0,trove:0,truediv:24,truthi:[3,8,15,18,24],tuck:[3,8,18,24],tupl:[3,5,8,18,23,24],turn:[2,3,5,18,24],twice:[11,13],two:[2,3,6,8,9,11,12,13,15,16,17,18,19,20,23,24],type:[0,1,4,8,11,13,15,20,21,22,23],type_check:24,typeerror:18,typeless:18,typic:[2,3,12,13],unari:8,unarybuiltinwrapp:3,unbalanc:[11,21],unbound:24,unchang:11,uncompil:18,uncon:[3,7,8,11,13,16,19,24],under:[2,3,8,11],underli:[5,15,18],underscor:18,understand:[0,11],undistinguish:11,undocu:8,unfinish:5,unfortun:23,unicod:18,unif:[18,20],unifi:[17,24],union:5,uniqu:[3,5,11,18],unit:[3,8,13,15,24],univers:[0,8,15,18,24],unlik:15,unnecessari:20,unnecesssari:18,unpack:[2,3,11,23],unpair:6,unquot:[8,16],unrol:5,unstack:[3,18],unswon:[3,24],untangl:13,until:[5,7,15],unus:6,unusu:11,unwrap:5,updat:[0,17,20,24],uppercas:5,upward:15,usag:8,use:[0,2,3,4,5,6,7,8,9,10,11,12,13,14,16,19,20,23],used:[3,4,8,11,13,15,18,19,21,23,24],useful:[0,15,18],user:16,uses:[2,5,6,13],using:[7,11,12,13,16,19,24],usual:[0,2,13],util:[0,3,14,17,18],valid:18,valu:[0,2,3,6,8,9,12,13,14,15,16,18,20,23,24],value_n:11,valueerror:[5,18,23],variabl:[18,20,24],variant:11,variat:[13,15,20],varieti:[4,8],variou:0,vener:23,verbos:4,veri:[0,1,4,5,8,11,23],versa:[2,18],version:[0,1,2,5,7,10,16,19,20],via:8,vice:[2,18],view:[11,20],viewer:[1,8,10,22],vii:20,visibl:18,von:[0,2,3,4,13],waaaai:5,wai:[0,2,3,4,5,6,8,13,14,15,18],wait:15,want:[2,6,7,9,11,13,18],warranti:[3,8],wash:8,wast:8,web:23,websit:[0,6],welcom:8,well:[0,4,8,9,11,18,21],went:18,were:[8,18,19],what:[2,3,4,5,8,11,13,15,16,18,22],whatev:[2,3,13,16,23],when:[6,7,8,11,13,15,18,19,21,23,24],where:[2,3,5,8,11,13,18,20,23],whether:13,which:[0,1,5,6,8,9,11,13,15,16,18,19,23,24],whole:[2,3,6,13,16,18],whose:7,why:[9,15,16],wiki:11,wikipedia:[0,11,19],wildli:8,wind:8,wire:13,within:[8,11,14,20],without:[2,8,11,12,15,18],won:[11,18,23],word:[0,3,6,8,13,19],work:[0,3,5,6,7,8,9,11,12,13,15,16,19,20,23,24],worker:15,worri:15,worth:6,would:[2,6,7,8,9,11,13,15,18,19,23,24],wrap:[3,8],wrapper:18,write:[4,5,9,11,13,15,16,18,19,20,23],written:[0,1,9,11,14,18,23],wrong:2,wrote:18,xrang:18,yang:18,yeah:15,year:[8,18],yet:[11,15,18,19,24],yield:[2,3,13,18,23,24],yin:20,you:[0,2,3,5,6,7,8,10,11,12,13,14,15,16,18,19,22,23],your:[2,3,8,13,18],yourself:[5,8,11],zero:[3,5,11,13,15,16,18,21,23,24],zip:[5,6,18],zip_:3,zipper:[0,20],zstr:19},titles:["Thun 0.2.0 Documentation","Joy Interpreter","Functions Grouped by, er, Function with Examples","Function Reference","Categorical Programming","\u2202RE","Developing a Program in Joy","Using x to Generate Values","Thun: Joy in Python","Newton\u2019s method","No Updates","Treating Trees I: Ordered Binary Trees","Quadratic formula","Recursion Combinators","Replacing Functions in the Dictionary","The Four Fundamental Operations of Definite Action","Treating Trees II: treestep","Type Checking","The Blissful Elegance of Typing Joy","Traversing Datastructures with Zippers","Essays about Programming in Joy","Parsing Text into Joy Expressions","Tracing Joy Execution","Stack or Quote or Sequence or List\u2026","Type Inference of Joy Expressions"],titleterms:{"\u03bb":5,"\u03d5":5,"case":[9,11],"function":[2,3,5,8,9,11,13,14,15,16,18],"long":14,"new":11,"p\u00f6ial":18,"try":5,"void":2,"while":[2,15],Adding:11,One:[7,11],The:[6,8,11,13,15,16,18],There:8,Using:7,With:[5,16],about:20,action:15,add:[2,11],adding:11,address:19,alphabet:5,altern:16,ana:13,analysi:6,anamorph:[2,13],app1:2,app2:2,app3:2,appendix:[11,13,18],appli:15,approxim:9,argument:18,auto:3,averag:2,base:[9,11],binari:[2,11,16],bliss:18,both:11,branch:[2,11,15],brzozowski:5,can:11,cata:13,catamorph:13,categor:4,chatter:2,check:17,child:11,choic:2,clear:2,cleav:[2,15],cmp:11,code:[8,11],combin:[2,11,13,18],comment:18,compact:5,compar:11,comparison:2,compil:[7,18],compile_:18,compos:18,comput:9,con:[2,18],concat:2,conclus:[13,18],consecut:9,continu:8,current:11,datastructur:[5,8,11,19],deal:18,defin:[11,16],definit:[12,15],delabel:18,delet:11,deriv:[5,12,13,16],design:13,determin:19,develop:6,diagram:5,dialect:0,dictionari:14,dip:[2,19],dipd:2,dipdd:2,direco:7,disenstacken:2,distinguish:18,div:2,doc_from_stack_effect:18,document:0,doe:11,down_to_zero:2,drive:5,drop:2,dup:[2,18],dupd:2,dupdip:2,effect:18,eleg:18,els:11,empti:11,enstacken:2,equal:11,essai:20,euler:[6,7],eval:8,even:7,exampl:[2,8,11,13,16,17],execut:22,explor:5,express:[5,8,21,24],extract:16,factori:13,fail:17,fibonacci:7,filter:6,find:[9,11,13],finish:15,finit:5,first:[2,6,15,18],five:7,flatten:2,flexibl:16,floordiv:2,formula:12,found:11,four:[13,15],fsm:5,fulmin:15,fun:13,fundament:15,further:6,gcd:2,gener:[3,5,6,7,9],genrec:2,get:[11,16],getitem:2,given:16,greater:11,group:2,handl:15,have:[11,16],help:2,highest:11,host:0,how:[6,7],hybrid:18,hylo:13,hylomorph:13,identifi:18,ift:[2,15],iii:18,implement:[5,18],indic:0,infer:[18,24],inferenc:18,inform:0,infra:[2,19],integ:6,interest:7,interlud:11,intern:21,interpret:[1,8,18],item:19,iter:[6,11],joi:[0,1,3,6,8,13,18,19,20,21,22,23,24],join:15,just:6,kei:11,kind:15,languag:0,larger:5,least_fract:2,left:11,less:11,let:[5,6],letter:5,librari:[3,8,18],like:11,list:[2,23],literari:8,littl:6,logic:[2,18],loop:[2,8,15],lower:11,lshift:2,machin:5,make:[7,9],mani:6,map:[2,15],match:5,math:2,memoiz:5,method:9,min:2,miscellan:2,mod:2,modifi:18,modulu:2,more:11,most:11,mul:[2,18],multipl:[6,7,18],must:11,name:12,neg:2,newton:9,next:9,node:11,non:11,now:11,nullari:2,nulli:5,number:[13,18],one:8,onli:8,oper:15,order:[11,16],osdn:0,other:15,our:11,out:5,over:2,pack:6,pam:[2,15],para:13,paradigm:18,parallel:15,parameter:[11,16],pars:[2,21],parser:[8,21],part:18,pass:8,path:19,pattern:13,per:11,polytyp:24,pop:[2,18],popd:2,popop:2,pow:2,power:7,pred:2,predic:[6,9,11,16],pretty_print:22,primit:13,primrec:2,print:8,problem:[6,7],process:11,product:2,program:[4,6,12,16,20],progress:18,project:[0,6,7],pure:8,put:[11,12,16],python:[8,14,18],quadrat:12,quick:0,quot:[2,23],rang:[2,6,13],range_to_zero:2,read:8,recur:[9,11],recurs:[11,13,16],redefin:[11,16],refactor:[6,11],refer:3,regular:[5,8],reimplement:16,relabel:18,rem:2,remaind:2,remov:2,render:6,repl:8,replac:[11,14],repres:[5,18],represent:5,reset:7,rest:[2,18],revers:[2,5,17],right:[11,19],rightmost:11,roll:[2,18],rolldown:2,rollup:2,rshift:2,rule:[5,18],run:[2,7],second:[2,18],select:2,sequenc:[7,15,18,23],set:[9,11],shorter:14,should:8,shunt:2,simpl:18,simplest:6,size:[2,14],sourc:11,special:[13,18],sqr:[2,18],sqrt:[2,12],stack:[2,8,18,23],start:0,state:5,step:[2,13,16],straightforward:12,stream:5,string:5,structur:11,style:8,sub:[2,11],subtyp:18,succ:2,sum:[2,6],swaack:2,swap:[2,18],swon:2,swoncat:2,symbol:[8,13],tabl:0,tail:13,take:2,term:[6,7,16],ternari:2,text:21,than:11,them:12,thi:11,third:[2,18],three:7,thun:[0,8],time:[2,7],togeth:[11,12,16],token:8,toler:9,trace:[14,22],traceprint:8,trampolin:5,travers:[11,16,19],treat:[11,16],tree:[11,16,19],treegrind:16,treestep:16,triangular:13,truediv:2,truthi:2,tuck:2,two:[5,7],type:[17,18,24],unari:2,unbound:18,uncon:[2,18],unif:17,unifi:18,unit:2,unnecessari:6,unquot:2,unstack:2,updat:[10,18],use:18,util:[22,23,24],valu:[7,11],variabl:12,variat:7,version:[6,11,14,18],view:8,vii:18,within:9,word:2,work:[17,18],write:12,xor:2,yin:18,zero:7,zip:2,zipper:19}}) \ No newline at end of file +Search.setIndex({docnames:["index","joy","lib","library","notebooks/Categorical","notebooks/Derivatives_of_Regular_Expressions","notebooks/Developing","notebooks/Generator_Programs","notebooks/Intro","notebooks/Newton-Raphson","notebooks/NoUpdates","notebooks/Ordered_Binary_Trees","notebooks/Quadratic","notebooks/Recursion_Combinators","notebooks/Replacing","notebooks/The_Four_Operations","notebooks/Treestep","notebooks/TypeChecking","notebooks/Types","notebooks/Zipper","notebooks/index","parser","pretty","stack","types"],envversion:52,filenames:["index.rst","joy.rst","lib.rst","library.rst","notebooks/Categorical.rst","notebooks/Derivatives_of_Regular_Expressions.rst","notebooks/Developing.rst","notebooks/Generator_Programs.rst","notebooks/Intro.rst","notebooks/Newton-Raphson.rst","notebooks/NoUpdates.rst","notebooks/Ordered_Binary_Trees.rst","notebooks/Quadratic.rst","notebooks/Recursion_Combinators.rst","notebooks/Replacing.rst","notebooks/The_Four_Operations.rst","notebooks/Treestep.rst","notebooks/TypeChecking.rst","notebooks/Types.rst","notebooks/Zipper.rst","notebooks/index.rst","parser.rst","pretty.rst","stack.rst","types.rst"],objects:{"joy.joy":{joy:[1,1,1,""],repl:[1,1,1,""],run:[1,1,1,""]},"joy.library":{"void":[3,1,1,""],BinaryBuiltinWrapper:[3,1,1,""],DefinitionWrapper:[3,2,1,""],FunctionWrapper:[3,1,1,""],SimpleFunctionWrapper:[3,1,1,""],UnaryBuiltinWrapper:[3,1,1,""],add_aliases:[3,1,1,""],app1:[3,1,1,""],app2:[3,1,1,""],app3:[3,1,1,""],b:[3,1,1,""],branch:[3,1,1,""],choice:[3,1,1,""],clear:[3,1,1,""],cmp_:[3,1,1,""],concat_:[3,1,1,""],cond:[3,1,1,""],dip:[3,1,1,""],dipd:[3,1,1,""],dipdd:[3,1,1,""],divmod_:[3,1,1,""],drop:[3,1,1,""],dupdip:[3,1,1,""],floor:[3,1,1,""],genrec:[3,1,1,""],getitem:[3,1,1,""],help_:[3,1,1,""],i:[3,1,1,""],id_:[3,1,1,""],infer_:[3,1,1,""],infra:[3,1,1,""],initialize:[3,1,1,""],inscribe:[3,1,1,""],inscribe_:[3,1,1,""],loop:[3,1,1,""],map_:[3,1,1,""],max_:[3,1,1,""],min_:[3,1,1,""],parse:[3,1,1,""],pm:[3,1,1,""],pred:[3,1,1,""],remove:[3,1,1,""],reverse:[3,1,1,""],select:[3,1,1,""],sharing:[3,1,1,""],shunt:[3,1,1,""],sort_:[3,1,1,""],sqrt:[3,1,1,""],step:[3,1,1,""],succ:[3,1,1,""],sum_:[3,1,1,""],take:[3,1,1,""],times:[3,1,1,""],unique:[3,1,1,""],unstack:[3,1,1,""],warranty:[3,1,1,""],words:[3,1,1,""],x:[3,1,1,""],yin_functions:[3,1,1,""],zip_:[3,1,1,""]},"joy.library.DefinitionWrapper":{add_def:[3,3,1,""],add_definitions:[3,3,1,""],parse_definition:[3,3,1,""]},"joy.parser":{ParseError:[21,4,1,""],Symbol:[21,2,1,""],text_to_expression:[21,1,1,""]},"joy.utils":{generated_library:[3,0,0,"-"],pretty_print:[22,0,0,"-"],stack:[23,0,0,"-"],types:[24,0,0,"-"]},"joy.utils.generated_library":{ccons:[3,1,1,""],cons:[3,1,1,""],dup:[3,1,1,""],dupd:[3,1,1,""],dupdd:[3,1,1,""],first:[3,1,1,""],first_two:[3,1,1,""],fourth:[3,1,1,""],over:[3,1,1,""],pop:[3,1,1,""],popd:[3,1,1,""],popdd:[3,1,1,""],popop:[3,1,1,""],popopd:[3,1,1,""],popopdd:[3,1,1,""],rest:[3,1,1,""],rolldown:[3,1,1,""],rollup:[3,1,1,""],rrest:[3,1,1,""],second:[3,1,1,""],stack:[3,1,1,""],stuncons:[3,1,1,""],stununcons:[3,1,1,""],swaack:[3,1,1,""],swap:[3,1,1,""],swons:[3,1,1,""],third:[3,1,1,""],tuck:[3,1,1,""],uncons:[3,1,1,""],unit:[3,1,1,""],unswons:[3,1,1,""]},"joy.utils.pretty_print":{TracePrinter:[22,2,1,""]},"joy.utils.pretty_print.TracePrinter":{go:[22,5,1,""],viewer:[22,5,1,""]},"joy.utils.stack":{concat:[23,1,1,""],expression_to_string:[23,1,1,""],iter_stack:[23,1,1,""],list_to_stack:[23,1,1,""],pick:[23,1,1,""],stack_to_string:[23,1,1,""]},"joy.utils.types":{AnyJoyType:[24,2,1,""],BooleanJoyType:[24,2,1,""],CombinatorJoyType:[24,2,1,""],FloatJoyType:[24,2,1,""],FunctionJoyType:[24,2,1,""],IntJoyType:[24,2,1,""],JoyTypeError:[24,4,1,""],KleeneStar:[24,2,1,""],NumberJoyType:[24,2,1,""],StackJoyType:[24,2,1,""],SymbolJoyType:[24,2,1,""],TextJoyType:[24,2,1,""],compilable:[24,1,1,""],compile_:[24,1,1,""],compose:[24,1,1,""],delabel:[24,1,1,""],doc_from_stack_effect:[24,1,1,""],infer:[24,1,1,""],meta_compose:[24,1,1,""],poly_compose:[24,1,1,""],reify:[24,1,1,""],relabel:[24,1,1,""],type_check:[24,1,1,""],uni_unify:[24,1,1,""]},"joy.utils.types.BooleanJoyType":{accept:[24,6,1,""]},"joy.utils.types.FloatJoyType":{accept:[24,6,1,""]},"joy.utils.types.IntJoyType":{accept:[24,6,1,""]},"joy.utils.types.KleeneStar":{kind:[24,6,1,""]},"joy.utils.types.StackJoyType":{accept:[24,6,1,""]},"joy.utils.types.TextJoyType":{accept:[24,6,1,""]},joy:{joy:[1,0,0,"-"],library:[3,0,0,"-"],parser:[21,0,0,"-"]}},objnames:{"0":["py","module","Python module"],"1":["py","function","Python function"],"2":["py","class","Python class"],"3":["py","classmethod","Python class method"],"4":["py","exception","Python exception"],"5":["py","method","Python method"],"6":["py","attribute","Python attribute"]},objtypes:{"0":"py:module","1":"py:function","2":"py:class","3":"py:classmethod","4":"py:exception","5":"py:method","6":"py:attribute"},terms:{"05s":5,"0b11100111011011":6,"23rd":18,"5bkei":11,"\u03b4":5,"\u03b5":9,"abstract":[8,11],"boolean":[2,3,8,11,15],"break":[5,8,18],"byte":[5,6],"case":[2,3,13,15,16,18,23],"char":5,"class":[3,5,8,18,21,22,23,24],"default":[3,7,11,23],"export":[3,21],"final":[2,11,13],"float":[3,8,18,19,21,24],"function":[0,1,4,6,7,10,12,17,19,20,21,22,23,24],"g\u00e9rard":19,"goto":5,"import":[2,5,6,7,9,11,12,13,14,16,17,18,19],"int":[5,7,8,13,18,19,21,23,24],"long":[11,18,20],"new":[2,3,5,7,8,10,13,14,18,24],"p\u00f6ial":20,"p\u00f6ial06typingtool":18,"public":10,"return":[1,3,5,6,8,11,13,14,15,16,18,21,22,23,24],"static":[2,10],"super":18,"switch":[2,18],"throw":[11,24],"true":[2,3,5,6,13,15,18,24],"try":[7,9,12,13,16,17,18,20],"void":[0,3],"while":[3,5,8,11,18,21,23],AND:[5,18],Adding:[8,14,20],And:[5,6,7,9,11,13,15,18,19,23],But:[0,4,6,7,8,11,14,18],CPS:8,For:[2,3,11,13,14,18,20,23,24],Its:3,NOT:5,Not:18,One:[2,8,15,18,20],REs:5,TOS:[2,3],That:[6,11],The:[0,1,2,3,4,5,7,9,10,12,19,20,21,23,24],Then:[2,3,11,12,13,18],There:[5,12,13,15,16,18,23],These:[15,18,20,23,24],Use:[3,9,13],Used:15,Using:[0,9,11,20],With:[9,13,18,20,24],_1000:18,__add__:18,__builtin__:24,__call__:5,__class__:18,__eq__:18,__ge__:18,__hash__:18,__init__:[5,18],__main__:18,__radd__:18,__repr__:18,__str__:22,_and:5,_compaction_rul:5,_con:5,_dictionari:18,_ge:18,_infer:18,_interpret:18,_log:18,_log_it:18,_names_for:18,_or:5,_templat:5,_to_str:18,_tree_add_:11,_tree_add_e:[11,24],_tree_add_p:11,_tree_add_r:11,_tree_add_t:11,_tree_delete_:11,_tree_delete_clear_stuff:[11,24],_tree_delete_del:11,_tree_delete_r0:[11,24],_tree_delete_r1:11,_tree_delete_rightmost:11,_tree_delete_w:11,_tree_get_:[11,24],_tree_get_p:11,_tree_get_r:11,_tree_get_t:11,_tree_iter_order_curr:11,_tree_iter_order_left:11,_tree_iter_order_r:11,_tree_iter_order_right:11,_tree_t:11,_treestep_0:16,_treestep_1:16,_uniqu:18,_within_b:9,_within_p:9,_within_r:9,a10001:18,a10002:18,a10003:18,a10004:18,abbrevi:16,abl:[5,15,18,24],about:[0,8,11,15,18,19,23],abov:[0,5,6,9,11,13,15,18],abs:9,absolut:8,accept:[1,2,3,5,6,7,8,11,12,14,15,16,18,19,24],accord:5,accordingli:[11,15],accumul:6,act:[5,24],action:[0,8,14,18,19,20],actual:[2,6,8,11,15,18],adapt:20,add:[3,5,6,7,8,14,18,22,24],add_alias:3,add_def:3,add_definit:[3,11,16],added:[4,11],adding:[10,18],addit:[0,2,3,6,8,13,14,16],address:20,adjust:11,advantag:18,affect:[3,15],after:[5,6,7,8,13,15,18,24],afterward:8,again:[2,3,6,8,11,13,18,24],against:[18,24],aggreg:19,ahead:18,aka:[5,8,19,24],albrecht:0,algorithm:[5,8,18],alia:[3,24],alias:[3,8],align:[8,22],all:[3,5,6,7,8,11,13,14,15,16,18,22,24],alloc:18,allow:[10,11,15],almost:11,along:[5,8,13,18,24],alphabet:[3,20],alreadi:[5,9,14,18,19],also:[0,5,6,8,11,15,18,23,24],alter:[5,18],altern:[4,18,24],although:[4,11],altogeth:7,alwai:[6,10,13,15],amend:15,among:18,amort:11,analysi:[4,20],anamorph:[8,20],ani:[4,5,6,8,10,11,15,18,19,21,24],annual:8,anonym:11,anoth:[5,11,15,18,23,24],anyhow:[15,18],anyjoytyp:[18,24],anymor:18,anystarjoytyp:18,anyth:[2,3,5,8,18,24],apart:18,api:10,app1:3,app2:[3,8,12,13,14,15],app3:[3,15],app:8,appear:[2,4,5,6,11,24],append:18,appendix:20,appli:[2,3,6,7,11,13,18,24],applic:7,approach:6,appropri:5,approxim:20,archiv:0,aren:19,arg:[2,3],argument:[2,3,8,9,12,13,20,22,23],arithmet:2,ariti:[2,15],around:[6,18,21,23],arrang:16,arriv:[7,16],arrow:5,articl:[0,4,7,13],ascii:5,ascii_lowercas:5,ask:[4,7,18],aspect:0,assembl:5,assert:[5,18],assign:[15,23],associ:11,assum:9,asterisk:16,asterix:[18,24],asyncron:15,attack:8,attempt:[0,1,3,18],attribut:3,attributeerror:18,author:18,auto:[0,18,24],automat:[4,15,18,24],auxiliari:[5,16],avail:[0,18,24],averag:[8,14],avoid:[11,24],awai:[11,18],awar:2,awkward:[11,13,18],azur:20,back:[11,18],backtrack:24,backward:[10,11,12,16],bad:18,bag:8,banana:13,bar:15,barb:13,base:[0,2,3,10,13,16,18],basestr:24,basic:[2,3,8,11],basicconfig:[17,18],becaas:5,becaus:[2,3,5,8,11,15,16,18,19,23,24],becom:[11,16,23],becuas:18,been:[5,9,10,11,18,19],befor:[5,7,8,11],begin:[11,16],behavior:[10,16,24],behaviour:[0,1,18,24],behind:15,being:[0,15,24],below:[2,3,5,6,7,11,18,19],bespok:8,best:0,better:[6,11,13,18],between:[0,6,24],beyond:7,biannual:8,bin:5,binari:[0,7,8,20],binary_search_tre:11,binarybuiltinwrapp:3,bind:8,bingo:19,bit:[5,6,7,11,18],blank:21,bliss:[0,20],block:6,bodi:[2,3,5,8,11,15],body_text:3,booktitl:18,bool:[13,18,24],booleanjoytyp:24,borrow:[8,18],both:[2,6,8,12,13,14,15,18,23],bottom:7,bounce_to:5,bracket:[8,18,21],branch:[3,5,6,7,13,18,20,24],branch_fals:18,branch_tru:18,breakpoint:8,bring:[6,8,18],bruijn:18,brutal:15,brzozowski:[18,20],brzozowskian:5,btree:[11,16],buck:11,bug:[0,8],build:[7,8,12,13,19,23],built:[12,18],bundl:[2,3,13],burgeon:8,calculu:4,call:[1,2,5,8,10,11,13,15,18,22,23],caller:[11,18],can:[0,2,3,4,5,6,7,8,9,10,12,13,14,15,16,18,19,20,21,23,24],cancel:15,cannot:[17,18,21],captur:8,card:8,care:[6,23],carefulli:19,carri:[7,11,24],cartesian:4,catamorph:20,categor:[0,20],categori:[4,15],ccc:4,ccon:[3,11,17,18,24],cell:[13,18],certain:[8,23],certainli:11,chain:[3,15],chang:[2,10,11,18,19],charact:[5,19],chat:8,chatter:[0,18],check:[0,7,9,18,20,24],child:16,choic:[3,13],choos:10,chop:12,chose:5,cinf:11,circl:5,circuit:4,cite_not:11,classmethod:3,claus:[3,18],clean:18,clear:[3,6,8],clear_stuff:11,cleav:[8,12,14],close:[0,1,4],clunki:[6,18],clv:15,cmp:[3,16,20],cmp_:3,code:[0,1,4,5,12,13,15,18,20,24],codireco:[7,9],collaps:13,collect:[4,5,7,8,18],collis:24,combin:[0,3,6,7,8,9,12,15,16,19,20,24],combinatorjoytyp:[18,24],come:[8,11,18],command:[8,11,18],comment:[15,24],common:[2,6,15],compar:[3,4,5,18],comparison:[0,11],compat:15,compel:4,compil:[2,3,4,5,8,11,14,15,20,24],compile_:24,complement:5,complet:[3,4],complex:[3,15,18,19,24],complic:18,compos:[5,24],composit:[18,24],compostit:18,compound:11,comput:[2,4,5,6,8,12,15,18,24],con:[3,5,6,7,8,9,11,12,13,15,16,19,23,24],conal:[4,15],concat:[3,7,8,15,16,18,23],concat_:3,concaten:[0,5],concatin:[0,3,5,23],concern:15,conclus:20,concurr:2,cond:[3,11],condit:[3,8],confer:18,conflict:[11,18,24],consecut:20,consid:[5,6,7,11,13,16,18,19],consist:[2,7,8,15,16],constant:11,constitu:13,construct:[15,18],consum:[15,18],contain:[0,2,3,5,7,8,13,18,21],content:18,context:2,conting:11,continu:[0,5,13,18,19],control:8,conveni:[4,15,18],convent:15,convers:18,convert:[13,14,16,18,21,23],cool:11,copi:[2,3,6,11,13,15,16,17,20],copyright:8,correspond:[4,15],could:[2,4,5,6,8,10,11,15,18,19],couldn:15,count:[3,18],counter:[6,18],coupl:16,cours:[6,11,18],cover:18,cpu:15,crack:11,crash:11,creat:[0,2,3,6,9,11,15,18],creativ:18,crude:[11,18,21,24],cruft:18,curent:24,current:[2,3,8,13,15,16,18,19,22,24],curri:5,custom:10,cycl:[6,7],cython:8,d010101:5,d0101:5,d01:5,d10:5,d_compact:5,dai:8,data:[2,3,5,13],datastructur:[0,2,13,18,20,21,23],datatyp:23,ddididi:19,deal:[0,5,11,15],dealt:18,debugg:18,decid:11,declar:18,decor:3,decoupl:13,decrement:3,deduc:[6,18],deeper:0,deepli:4,def:[3,5,8,13,14,18,23],defaultdict:[5,18],defi:3,defin:[2,3,4,5,6,7,8,9,10,12,13,14,15,18,19,20],definit:[0,2,3,6,7,8,10,11,13,16,18,20,24],definitionwrapp:[3,11,13,16],defint:15,del:17,delabel:24,deleg:8,delet:20,deliber:18,demo:18,demonstr:4,depend:[3,11,13,15],deposit:16,depth:[18,24],dequot:13,der:11,deriv:[2,3,6,8,9,11,18,20],derv:5,describ:[3,4,5,11,13,15,16,18,21,24],descript:[6,8],descriptor:18,design:[2,3,11,15,20],desir:[8,16],destin:5,destruct:11,detail:[8,11,18],detect:[5,7,11,13,18],determin:20,develop:[0,7,8,18,20],diagram:6,dialect:1,dict:[1,3,5,18,24],dictionari:[0,1,3,8,18,20],did:18,differ:[0,4,6,9,11,12,13,15,23],differenti:4,difficult:18,difficulti:15,dig:[11,19],digit:6,digraph:5,dinfrirst:[8,18,24],dip:[3,6,7,8,9,11,12,13,14,15,16,18,20,24],dipd:[3,7,8,11,12,13,15,18,19,24],dipdd:[3,11],direco:20,direct:8,directli:[6,15,16,18,23],disappear:[2,5,18,24],discard:[3,7,9,11,13],disciplin:11,disctionari:1,disenstacken:8,disk:8,displac:2,displai:18,distiguish:18,distribut:15,ditch:11,div:[3,8,18,24],dive:16,divis:11,divmod:[3,24],divmod_:[3,18],doc:[2,3,8,18,24],doc_from_stack_effect:[17,24],docstr:18,document:[18,20,21,23],doe:[0,1,3,4,5,7,8,14,15,18,20,22,24],doesn:[6,10,11,15,16,18,23],doing:[4,6,8,15,18,19],domain:[4,18],don:[5,6,8,11,18,24],done:[2,6,8,10,18],dooooc:18,door:8,dot:[5,22],doubl:[3,5,6,8,18],doublecircl:5,down:[2,5,9,13,19,24],down_to_zero:8,dozen:8,draft:[4,10],dream:8,drive:[7,9],driven:6,driver:[5,7],drop:[3,11],dudipd:8,due:18,dup:[3,6,7,8,9,11,12,13,15,17,19,23,24],dupd:[3,18,24],dupdd:[3,24],dupdip:[3,6,11,12,13],duplic:[3,11,13],durat:2,dure:[2,13],each:[2,3,4,5,6,8,13,14,15,16,18,22,24],easi:[0,11,16,18,19],easier:[3,11,15],easili:4,eat:5,edit:20,effect:[2,3,5,8,15,19,20,24],effici:[7,14,19],efg:18,either:[1,2,3,5,11,13,18],elabor:18,eleg:[0,5,8,11,15,20],element:2,elif:18,elimin:[5,18],elliott:[4,15],els:[2,3,5,13,15,18],else_:18,embed:[4,11,19],emit:18,empti:[3,5,8,16,18,23,24],encapsul:8,enclos:8,encod:7,encount:18,end:[5,6,11,13,16,18,23],endless:7,enforc:[2,8],engend:8,enough:[5,8,13,22,24],enstacken:[7,8,18],enter:[3,8,24],enter_guard:18,entir:23,entri:[3,19,22],enumer:18,epsilon:9,equal:[3,6,16,23],equat:[8,9],equival:15,ergo:[5,11],err:[11,17],error:[8,18,21],essai:0,establish:18,etc:[3,16,18,19,21],euler:20,euro:18,eval:[0,18],evalu:[1,2,3,8,9,11,12,13,14,15,16,18],event:15,eventu:[15,18],ever:18,everi:[1,7,15],everybodi:15,everyth:[3,5,11,12,15,18],evolv:10,examin:13,exampl:[0,3,5,6,18,20,21,23,24],exce:7,except:[5,8,11,17,18,21,24],execut:[0,1,2,3,8,13,14,15,16,18,19,23,24],exend:18,exercis:[5,11],exist:[4,11,18],expand:11,expect:[2,3,15,16,18,23,24],experi:[8,16],explain:18,explan:8,explor:[8,18],express:[0,1,2,3,4,11,13,14,18,19,20,22,23],expression_to_str:[18,23],extend:18,extra:[6,7],extract:[11,12,20],extrem:8,extrememli:8,f_g:18,f_in:18,f_out:18,f_python:18,facet:0,facil:8,fact:21,factor:[2,6,8,11,18],factori:20,fail:[2,3,11,20,21,24],fail_fail:3,fairli:18,fake:5,fall:18,fals:[2,3,5,6,13,15,18,24],falsei:18,far:[9,11,13,18,24],fascin:0,favorit:15,fear:[11,18],few:[6,8,9,12,15,18],fewer:[3,8],fg_in:18,fg_out:18,fib:7,fib_gen:7,fibonacci:20,figur:[2,3,11,13,18],filter:11,fin:6,find:[2,3,5,6,7,15,16,18,20],finder:9,fine:[0,5,6,11,18,24],finite_state_machin:5,first:[3,5,7,8,9,11,12,13,14,16,19,20,24],first_two:[3,11,24],fit:[6,8],five:[6,8,20],fix:[2,3,5,13,18,24],fixm:[5,18],flag:[15,18],flatten:[8,16,18],flesh:5,flexibl:20,floatjoytyp:[18,24],floatstarjoytyp:18,floor:3,floordiv:[6,24],flow:8,follow:[0,2,3,5,8,10,13,15,16,18,19,24],foo:[8,10,11,15,18],foo_ii:10,fork:15,form:[2,3,4,5,6,7,13,16,18,23],forman:8,format:[17,18,20,22],formula:[0,6,20],forth:[8,18],forum:0,forward:18,found:8,four:[0,2,3,6,7,8,11,20],fourteen:6,fourth:[2,3,11,13,24],fractal:8,fraction0:8,fraction:[2,8],frame:13,framework:8,free:[4,8,11],freeli:2,from:[0,1,2,3,5,6,7,8,9,11,12,13,14,15,16,17,18,19,20,23],from_:5,front:[2,3,13],frozenset:5,fulin:15,full:6,fun:[5,20],func:18,functionjoytyp:[18,24],functionwrapp:3,functool:5,fundament:[0,20],funtion:11,further:[9,18,20],futur:15,g_in:18,g_out:18,garbag:8,gari:11,gcd:8,gener:[0,2,4,13,15,18,20,23,24],generated_librari:3,genrec:[3,8,11,13,15,16,18],geometr:6,get:[2,4,5,6,7,8,12,13,18,20],getch:5,getitem:3,getrecursionlimit:23,getsourc:8,ghc:4,give:[4,6,11,13,16,18,23],given:[2,3,6,7,9,11,13,15,18,19,20],global:[17,18],glue:8,goe:24,going:[5,11,12,15,16,18,19],good:[6,11,18],grab:18,grammar:21,grand:8,graph:15,graphic:5,graphviz:5,great:[0,8,18,20],greater:23,grind:18,group:0,grow:5,gsra:9,guard:[11,18,24],had:[5,6,19],haiku:8,half:[6,18,19],hallmark:15,hand:[5,8,14,18,20],handi:[9,18],handl:[11,18,23,24],happen:[8,18],happi:5,hard:[5,18,19],hardwar:4,has:[0,2,5,7,8,9,10,11,13,15,18,19,23],hasattr:18,hash:18,haskel:4,have:[2,3,5,6,7,8,9,10,13,14,15,18,19,20,23,24],haven:24,head:23,heh:18,help:[8,11,13,18],help_:3,helper:[3,5],herd:8,here:[5,6,7,11,16,18,19,24],hide:11,hierarchi:18,higher:[5,8,11,18],highli:8,hij:5,histori:[18,22,24],hit:5,hmm:[5,11],hoist:3,hold:[6,18],hood:11,hope:[0,6,8,20],hopefulli:13,host:20,how:[0,4,5,9,11,13,18,19,20],howev:[13,14,15,18],html:[2,3,7,12,13,20],http:11,huet:19,huge:11,hugh:[9,16],human:8,hybrid:24,hylomorph:20,hypothet:2,id_:3,idea:[4,6,8,18],ident:[3,5,13,18,24],if_not_empti:11,ift:[3,11,13,16,18,24],ignor:[1,3,11,18],iii:20,illustr:[5,13],imagin:[5,15,19],imap:18,imit:[5,16],immedi:[5,13],immut:[5,8,11],imper:13,implement:[0,1,2,3,4,8,10,11,13,14,15,20,24],implementaion:15,implicit:8,improv:18,includ:[4,11,15,16,18,24],inclus:6,incom:23,incompat:10,incorpor:12,increas:6,increment:[3,4,6,10,15],indetermin:24,index:[0,8,18,23],indexerror:23,indic:[15,16,18,24],ineffici:18,infer:[0,3,17],infer_:3,inferenc:24,info:[17,18],inform:[3,5,18,24],infra:[3,7,8,11,12,14,15,16,18,20,24],infrastructur:3,initi:[2,3,5,8,9,11,18],inlin:11,inner:18,inproceed:18,input:[1,9,15,17,18,24],input_:5,inscrib:3,inscribe_:3,insert:18,insight:13,inspect:8,inspect_stack:18,instal:0,instanc:18,instanti:[4,22],instead:[5,6,7,11,13,18,19,23,24],instruct:5,integ:[2,3,8,13,16,18,21],integr:3,intend:[0,8],interact:[8,20],interest:[0,6,11,18,20],interfer:15,interlud:20,intermedi:13,intern:[0,18,22,23],interpret:[0,4,10,14,21,22,24],interrupt:8,intersect:5,interspers:15,interv:[4,6],intjoytyp:[18,24],introduc:10,introduct:0,intstarjoytyp:18,intuit:18,invalid:24,invari:3,invent:18,involv:18,ipf:8,isinst:[5,18],isn:[5,11,19],issubclass:18,item:[2,3,8,11,13,15,16,18,20,23],iter:[1,3,5,8,13,15,16,18,20,23],iter_stack:[14,23],iteritem:[5,18],itertool:[5,18],its:[0,1,2,3,4,6,8,11,13,15,16,18,23],itself:[0,2,8,11,15,18,24],j05cmp:[2,3,13],jaanu:18,jmp:5,job:[15,20],john:[9,16],joi:[2,4,10,11,12,14,15,17],join:[5,18],joypi:[8,19],joytypeerror:[17,24],jump:5,jump_from:5,junk:18,jupyt:20,just:[0,2,3,5,7,8,10,11,13,15,16,18,19],juxtaposit:15,keep:[5,11,12,15,18,19],kei:[5,16,20],kevin:0,key_n:11,keyerror:[5,11,18],kind:[2,4,8,11,13,16,18,24],kinda:18,kleen:[16,18,24],kleenestar:[18,24],kleffner:18,know:[6,11,18],knowledg:18,known:[4,15],kstar:5,l_kei:11,l_left:11,l_right:11,l_valu:11,label:[5,18],lambda:[4,5,18],languag:[4,5,8,10,11,14,18],larg:[5,18],larger:[20,23],largest:3,last:[6,11,13,18],lastli:7,later:[5,8,16,18],law:2,lazi:18,lazili:9,lcm:6,lead:[5,8,18,24],leaf:11,lean:8,learn:0,least:[2,6,13,18,23],least_fract:8,leav:[6,15],left:[5,8,12,13,15,16,18,19,22,23,24],leftov:13,legend:5,len:[5,18],length:[3,6,23],lens:13,less:[6,7,8,13,18,23],let:[7,9,11,12,13,16,18,19,20],letter:18,level:[4,5,11,17,18],librari:[0,5,14],like:[2,3,5,6,8,15,16,18,20,21,24],limit:[18,24],line:[3,8,11,12,18,22,24],linear:23,link:[0,5,18],linux:0,list:[0,3,5,6,8,9,11,13,15,16,18,19,22,24],list_to_stack:[18,23],liter:[1,11,16,18,19,21],literatur:18,littl:[5,7,11,15,18,20],live:20,lkei:16,load:[6,8],local:18,locat:2,locu:22,log:[17,18],log_2:11,logic:[0,6,20],longer:[11,18],look:[1,5,7,8,9,11,12,15,18],lookup:8,loop:[0,1,3,5,6,18,20,24],lose:18,lot:[5,8,11,18,19],love:6,low:[4,5],lower:6,lowercas:[5,18],lowest:11,lshift:24,machin:[0,20],machineri:[11,18],macro:8,made:[0,8,15,18,19],magic:18,mai:[2,13,15],mail:0,main:[0,3,8,12,15,18,19],mainloop:10,maintain:19,major:10,make:[2,3,4,6,8,11,13,14,15,16,18,19,20],make_gener:9,make_graph:5,manfr:[0,2,3,4,13],mani:[0,5,8,18],manipul:18,manner:12,map:[1,3,5,6,8,10,13,16,18],map_:3,marker:8,mask:[6,7],match:[0,1,18,20],materi:0,math:[0,8,9,11,12,18],mathemat:8,matter:[6,9,11,16],max_:3,maximum:3,mayb:[11,18],mean:[3,4,6,8,9,11,13,16,18,23,24],meant:[8,11,13,16],mem:5,member:[2,3,13],memo:5,mental:8,mention:2,mercuri:0,mess:18,messag:[17,18],meta:[8,11,14],meta_compos:[18,24],method:[0,3,8,18,20,22],midpoint:6,might:[4,5,7,11,18],mike:11,million:7,min_:3,mind:18,minimum:3,minor:11,minu:3,mirror:0,miscellan:0,mismatch:18,mix:[8,18],mod:3,mode:18,model:[4,8],modern:0,modif:[7,18],modifi:[8,11,19],modul:[0,1,3,8,18,21],modulu:[8,24],moment:18,month:8,more:[0,3,4,5,6,7,8,9,13,14,15,16,18,21,23,24],most:[5,18,24],mostli:0,move:[5,11],movement:2,much:[5,6,7,11,13,18],muck:11,mul:[3,8,12,17,19,22,24],multi:3,multipl:[20,24],must:[2,3,6,10,13,15,16,18,21],myself:18,n10001:18,n10002:18,n10003:18,n1001:18,n1002:18,n1003:18,name:[1,3,5,8,10,11,13,18,19,20,21,23,24],narr:18,natur:[5,6,7,11,18],navig:19,nearli:18,neat:11,neato:18,necessarili:18,need:[2,3,6,7,9,10,11,13,15,18],neg:[3,12,24],neither:[15,18],ness:5,nest:[3,8,11,19],network:8,never:[5,10,13],new_def:18,new_f:18,new_fo:18,new_kei:11,new_valu:11,newton:[0,20],next:[5,6,15,16,18,24],nice:[0,5,13,23],niether:2,node:[5,16,20],node_kei:11,node_valu:11,non:[5,16,18,24],none:[1,3,18,24],nope:16,nor:5,normal:15,notat:[8,11],note:[2,5,6,9,11,13,15,18,23],notebook:[6,7,8,18,19,20],notebook_preambl:[2,6,7,9,11,12,13,14,16,18,19],noth:[2,11,15],notic:6,now:[5,6,7,8,13,14,16,18,20],nth:[3,23],nullari:[8,11,15,18,24],number:[1,2,3,6,7,9,15,23,24],numberjoytyp:[18,24],numberstarjoytyp:18,numer:18,object:[5,18,21],observ:6,obviou:7,obvious:18,occur:11,odd:[6,7],off:[2,3,6,7,12,18,19],often:[5,15],old:[2,14],old_k:11,old_kei:11,old_valu:11,omg:5,omit:[13,18,21],onc:[3,5,10,11],one:[2,3,5,6,7,11,13,15,16,18,22,23,24],ones:[5,7,18],onli:[2,3,5,6,11,13,15,18,19,23,24],onto:[1,2,3,8,13,23],open:[8,18],oper:[0,3,5,8,11,13,20,23],oppos:18,optim:11,option:[1,8,11,18,23],orchestr:15,order:[0,2,3,8,13,15,17,18,20,23],org:[0,11],origin:[0,1,2,3,11,19],other:[0,2,3,4,5,8,11,13,16,18,23,24],otherwis:[3,5,6,7,11,16,18,24],our:[5,6,7,8,9,13,16,18],out:[2,3,4,6,7,8,9,11,12,13,15,18,19,20],outcom:16,outlin:5,output:[5,9,13,15,17,18,24],outsid:4,over:[3,4,6,7,8,9,11,12,15,16,18,20,24],overhaul:18,overview:18,own:[11,18],pack:23,packag:[0,8],page:[0,11,18,23],pair:[2,3,6,7,11,18],palidrom:6,palindrom:6,pam:8,paper:[4,8,13,15,19],paradigm:20,parallel:[2,20],paramet:[1,2,3,13,14,21,22,23],parameter:20,paramorph:13,parenthes:[11,23],pariti:7,pars:[0,3,5,8],parse_definit:3,parseerror:21,parser:[0,17,18],part:[2,3,9,13,16,20],partial:[5,18],particular:19,pass:[0,5,11,18,22,24],patch:5,path:[5,18,20],pattern:[5,6,15,16,20],pe1:[6,7],pe2:7,pearl:19,pend:[3,8,13,18,19,22],peopl:20,per:[8,16],perfectli:15,perform:[5,15,18],perhap:7,period:8,permit:[15,18,23],permut:18,persist:[3,11],phase:2,phi:5,pick:[6,7,15,23],pickl:8,pictur:11,piec:13,pip:0,place:[3,6,8,18],plai:0,plu:3,plug:[7,13,16],point:[4,5,8,11,13,15],pointless:2,poly_compos:24,polytyp:[0,17,18],pool:15,pop:[3,5,6,7,8,11,13,14,16,17,23,24],popd:[3,8,9,11,14,15,18,24],popdd:[3,7,12,18,24],popop:[3,6,7,8,9,11,16,18,24],popopd:[3,24],popopdd:[3,24],posit:[3,6,8,13],possibilit:11,possibl:[11,16,18,20],post:8,poswrd:18,potenti:15,pow:24,power:[8,18],pprint:5,pragmat:6,preambl:9,preceed:15,precis:[0,1],pred:[3,18,24],predic:[2,3,5,7,13,15,24],prefix:[18,22],preliminari:5,present:18,preserv:[4,16],pretti:[9,11,12,15,16,18,22,23],pretty_print:0,previou:[8,15],prime:9,primit:[2,3,18,20],primrec:[3,7,8,9,13],print:[0,1,2,3,5,17,18,22,23,24],probabl:[7,8,11,18],problem:[8,18,20],proc_curr:11,proc_left:11,proc_right:11,proce:[6,24],process:[5,8,16,18,22],produc:[6,11,13,16,18],product:[5,7,8,17,18],program:[0,2,3,7,8,9,11,13,15,18,19,24],programm:[15,18],progress:15,project:20,prolog:18,promis:15,prompt:8,proper:[2,3,13,15,24],properti:0,provid:[0,3,4,8,15,18,24],pun:[0,8],punctuat:18,pure:[0,5],puriti:8,purpos:8,push:[2,3,8,13,19,23],pushback:8,put:[1,2,7,8,15,18,20,23],pypi:0,python:[0,2,3,5,11,13,15,19,20,21,23,24],quadrat:[0,20],queri:[11,16],query_kei:16,queu:13,quit:[0,16],quot:[0,3,7,8,11,12,13,15,16,18,19,22,24],quotat:[2,3,13],quotient:3,r_kei:11,r_left:11,r_right:11,r_valu:11,rais:[5,11,18,21,23],rang:[5,8,18],range_revers:13,range_to_zero:8,ranger:13,ranger_revers:13,rankdir:5,raphson:9,rather:[6,8,13,16],ratio:8,reach:[5,6,7,13],read:[0,1,6,7,11,18,19],readabl:14,reader:[5,11],readi:18,real:11,realiz:[4,11],rearrang:[2,3,11,18],reason:[6,8,15,18],rebuild:[16,19],rec1:[2,3,13],rec2:[2,3,13],recogn:21,recombin:15,record:[8,22],recur:[13,18],recurs:[0,2,3,5,7,8,9,15,18,20,23],recus:8,redefin:20,redistribut:[3,8],redo:5,reduc:[2,18],redund:23,refactor:[8,10],refer:[0,2],referenti:15,reflect:15,regard:15,regist:2,regular:[18,20,21],reifi:[17,24],reimplement:[15,20],relabel:24,relat:[5,18],releas:10,remain:[2,8,10,18],remaind:[3,9],rememb:5,remind:18,remov:[3,11,18,23],render:20,repeat:6,repeatedli:6,repetit:5,repl:[0,1],replac:[0,2,3,7,12,13,15,16,18,19,20,23],repositori:0,repr:[5,18],repres:[2,8,11,15,21,22,24],represent:[23,24],reprod:7,repurpos:18,requir:[15,18,23],res:18,research:18,resembl:8,resolut:15,resourc:[3,15],respect:[5,6,15],rest:[3,6,7,8,11,13,19,20,23,24],rest_two:11,restart:3,restor:2,result:[1,2,3,5,6,11,12,13,15,16,18,19],resum:8,retir:2,retri:8,reus:[11,18],revers:[3,6,7,13,18,19,20,23],revisit:18,rewrit:[3,8,18],rewritten:8,rid:11,right:[7,8,12,16,18,20,22,23,24],rightest:11,rightmost:6,rigor:15,risk:18,rkei:16,rob:18,roll:[3,9,11,16],roll_dn:18,rolldown:[3,17,18,24],rollup:[3,18,24],root:[3,9,12],round:18,row:5,rrest:[3,17,18,24],rshift:24,rule:[15,20],run:[0,1,3,6,8,9,11,12,13,15,16,18,19],runtim:15,runtimeerror:23,sai:[5,7,11,12,16,18],same:[2,4,6,11,15,18,23],sandwich:[2,3,13],save:[2,5,6,8],scan:3,scanner:[8,21],scenario:19,scope:[7,11],search:[0,11],sec:[18,24],second:[3,8,11,13,16,23,24],section:13,see:[0,5,7,8,9,10,12,13,14,18,19,22],seem:[0,6,8,16,18,24],seen:[18,19,24],select:3,self:[5,15,18],semant:[2,3,8,10,11,15,18],semi:8,send:8,sens:[0,2,6,18,19],separ:[8,15,18,21],seq:18,sequenc:[0,1,2,3,6,8,11,13,14,19,20,21,24],sequence_to_stack:18,seri:[6,7,11,19],ses:18,set:[2,3,5,13,18,20],seven:[6,7],sever:[0,4,8,13],shape:[5,15],share:[3,8],shelf:2,shew:5,shift:[6,7],shorter:20,shorthand:11,should:[2,3,5,6,11,13,15,18],shouldn:8,show:[4,15,18,19],shunt:[3,19],side:[5,11,17,18,24],sign:3,signatur:24,signifi:[8,11],similar:[11,16,18],simon:8,simpl:[5,8,13,23,24],simplefunctionwrapp:[3,14,18],simpler:16,simplest:[18,20],simpli:4,simplifi:[6,11,19],sinc:[2,6,11,18],singl:[3,7,8,14,15,18,21,24],singleton:5,situ:11,situat:11,six:[6,7,8],sixti:[6,7],size:[5,8,20],skeptic:8,skip:18,slight:9,slightli:[11,13,18],smallest:3,smart:11,softwar:8,solei:2,solut:[6,7],solvabl:8,some:[2,3,5,7,8,11,13,15,16,18,20,23,24],somehow:[11,18],someth:[2,10,11,18],sometim:11,somewher:[11,20],sort:[3,5,11,15,18],sort_:3,sourc:[0,1,3,18,20,21,22,23,24],space:[6,22],span:6,spawn:18,special:[7,11,20],specif:[0,4],specifi:[11,15,24],speed:14,spell:[5,16],sphinx:[20,23],spirit:[0,1,16],split:[5,18,24],sqr:[3,8,9,12,19],sqrt:[3,9,18,24],squar:[3,9,18,21],stack:[0,1,3,6,7,9,11,12,13,14,15,16,17,19,20,21,22,24],stack_effect:18,stack_effect_com:18,stack_to_str:[17,23],stacki:18,stackjoytyp:[18,24],stackstarjoytyp:18,stage:16,stai:[0,1],stand:[4,5],standard:[8,11],star:[16,18,24],stare:11,start:[5,6,7,8,9,11,13,16,18,24],state:[8,20],state_nam:5,statement:[3,5],stdout:[17,18],step:[3,6,8,11,14,18,19,20],still:[5,11,18],stop:11,stopiter:5,storag:[6,11],store:[6,13,18],stori:13,str:[1,5,18,21,22,23],straightforward:[5,7,9,18,20],stream:[6,17,18],stretch:11,string:[1,2,3,8,18,19,20,21,22,23,24],stringi:5,structur:[8,15,16,18,19,20,23],stuck:5,studi:5,stuff:[11,18],stuncon:[3,24],stununcon:[3,24],style:[0,4,18],sub:[10,15,24],subclass:8,subject:[15,19],subsequ:15,subset:[18,24],substitut:[5,11,18,24],subtract:6,subtyp:20,succ:[3,18,24],succe:18,success:9,suck:18,suffic:18,suffici:11,suffix:18,suggest:[4,5,11],suitabl:[3,4,6],sum:[3,7,8,12,13,14,16],sum_:[3,18],summand:6,sumtre:16,suppli:[11,21],support:[8,18,22,23],sure:15,suspect:2,svg:5,swaack:[3,12,14,18,19,24],swap:[3,6,7,8,9,11,13,14,15,16,17,19,24],swon:[3,7,8,13,16,18,19,24],swoncat:[7,8,9,13,16],swuncon:13,sym:5,symbol:[1,2,3,5,15,18,19,20,21],symboljoytyp:[18,24],symmetr:[6,11],symmetri:5,syntact:8,syntax:[8,23],sys:[17,18,23],system:[8,11,15],tabl:[5,18],tag:[5,18],tail:[11,18,20,23],take:[3,5,6,8,9,11,13,15,18,23],talk:[8,11,18,23],target:19,tast:4,tbd:8,tear:13,technic:2,techniqu:[4,19],technolog:2,temporari:19,ten:6,term:[1,2,5,8,9,13,15,18,20,21,23,24],termin:[2,3,5,13],ternari:8,test:[2,3,13],text:[0,1,3,18],text_to_express:[8,17,21],textjoytyp:24,textual:8,than:[0,3,5,6,7,8,9,13,15,16,18,23,24],thei:[2,3,5,6,7,8,11,13,15,18,19,21,23,24],them:[2,3,5,6,7,11,13,15,18,19,20,24],themselv:[15,18,24],theori:[2,3,13,15],therefor:7,thi:[0,1,2,3,4,5,6,7,8,9,12,13,15,16,18,19,20,21,22,23,24],thing:[2,7,11,13,15,18,19,21,23,24],think:[2,6,8,11,13,15,16,18],third:[3,7,8,11,24],thirti:6,those:[2,3,5,11,13,18,20,24],though:[6,15],thought:[8,15],thousand:6,thread:[2,15],three:[2,3,5,6,8,11,12,16,18,20],through:[1,6,8,16,18,19,23,24],thun:[2,3,4,10,13,15],thunder:8,thunk:15,time:[3,5,6,8,9,11,13,15,18,19],titl:18,to_check:5,to_set:11,todai:8,todo:[8,21],togeth:[7,8,15,18,20],token:21,toler:20,too:[5,13,18],tool:[8,18],tooo:18,top:[2,3,8,13,18,22,23],total:6,tower:18,trace:[0,8,12,13,19,20,23],traceprint:22,track:[12,18,19],tracker:0,transform:4,transit:5,translat:[4,12,18],trap:5,travers:[0,20],treasur:0,treat:[0,2,3,13,18,20],treatment:7,tree:[0,8,20],treegrind:20,treestep:[0,20],tri:6,triangl:15,triangular_numb:13,trick:[6,18],tricki:18,trinari:24,trobe:0,trove:0,truediv:24,truthi:[3,8,15,18],tuck:[3,8,18,24],tupl:[3,5,8,18,23,24],turn:[2,3,5,18,24],twice:[11,13],two:[2,3,6,8,9,11,12,13,15,16,17,18,19,20,23,24],txt:3,type:[0,1,4,8,11,13,15,20,21,22,23],type_check:24,typeerror:18,typeless:18,typic:[2,3,12,13],unari:8,unarybuiltinwrapp:3,unbalanc:[11,21],unbound:24,unchang:11,uncompil:18,uncon:[3,7,8,11,13,16,19,24],under:[2,3,8,11],underli:[5,15,18],underscor:18,understand:[0,11],undistinguish:11,undocu:8,unfinish:5,unfortun:23,uni_unifi:24,unicod:18,unif:[18,20],unifi:[17,24],union:5,uniqu:[3,5,11,18],unit:[3,8,13,15,24],univers:[0,8,15,18,24],unlik:15,unnecessari:20,unnecesssari:18,unpack:[2,3,11,23],unpair:6,unquot:[8,16,21],unrol:5,unstack:[3,18],unswon:[3,24],untangl:13,until:[5,7,15],unus:6,unusu:11,unwrap:5,updat:[0,17,20,24],uppercas:5,upward:15,usag:8,use:[0,2,3,4,5,6,7,8,9,10,11,12,13,14,16,19,20,23],used:[3,4,8,11,13,15,18,19,21,23,24],useful:[0,15,18],user:16,uses:[2,5,6,13],using:[7,11,12,13,16,19,24],usual:[0,2,13],util:[0,3,14,17,18],valid:18,valu:[0,1,2,3,6,8,9,12,13,14,15,16,18,20,21,23,24],value_n:11,valueerror:[5,18,23],variabl:[18,20,24],variant:11,variat:[13,15,20],varieti:[4,8],variou:0,vener:23,verbos:4,veri:[0,1,4,5,8,11,23],versa:[2,18],version:[0,1,2,5,7,10,16,19,20],via:8,vice:[2,18],view:[11,20],viewer:[1,8,10,22],vii:20,visibl:18,von:[0,2,3,4,13],waaaai:5,wai:[0,2,3,4,5,6,8,13,14,15,18],wait:15,want:[2,3,6,7,9,11,13,18],warranti:[3,8],wash:8,wast:8,web:23,websit:[0,6],welcom:8,well:[0,4,8,9,11,18,21],went:18,were:[8,18,19],what:[2,3,4,5,8,11,13,15,16,18,22],whatev:[2,3,13,16,23],when:[6,7,8,11,13,15,18,19,21,23,24],where:[2,3,5,8,11,13,18,20,23],whether:13,which:[0,1,5,6,8,9,11,13,15,16,18,19,21,23,24],whole:[2,3,6,13,16,18],whose:7,why:[9,15,16],wiki:11,wikipedia:[0,11,19],wildli:8,wind:8,wire:13,within:[8,11,14,20],without:[2,8,11,12,15,18],won:[11,18,23],word:[0,3,6,8,13,19],work:[0,3,5,6,7,8,9,11,12,13,15,16,19,20,23,24],worker:15,worri:15,worth:6,would:[2,6,7,8,9,11,13,15,18,19,23,24],wrap:[3,8],wrapper:18,write:[4,5,9,11,13,15,16,18,19,20,23],written:[0,1,9,11,14,18,23],wrong:2,wrote:18,xrang:18,yang:18,yeah:15,year:[8,18],yet:[11,15,18,19,24],yield:[2,3,13,18,23,24],yin:[3,20],yin_funct:3,you:[0,2,3,5,6,7,8,10,11,12,13,14,15,16,18,19,22,23],your:[2,3,8,13,18],yourself:[5,8,11],zero:[3,5,11,13,15,16,18,21,23,24],zip:[5,6,18],zip_:3,zipper:[0,20],zstr:19},titles:["Thun 0.2.0 Documentation","Joy Interpreter","Functions Grouped by, er, Function with Examples","Function Reference","Categorical Programming","\u2202RE","Developing a Program in Joy","Using x to Generate Values","Thun: Joy in Python","Newton\u2019s method","No Updates","Treating Trees I: Ordered Binary Trees","Quadratic formula","Recursion Combinators","Replacing Functions in the Dictionary","The Four Fundamental Operations of Definite Action","Treating Trees II: treestep","Type Checking","The Blissful Elegance of Typing Joy","Traversing Datastructures with Zippers","Essays about Programming in Joy","Parsing Text into Joy Expressions","Tracing Joy Execution","Stack or Quote or Sequence or List\u2026","Type Inference of Joy Expressions"],titleterms:{"\u03bb":5,"\u03d5":5,"case":[9,11],"function":[2,3,5,8,9,11,13,14,15,16,18],"long":14,"new":11,"p\u00f6ial":18,"try":5,"void":2,"while":[2,15],Adding:11,One:[7,11],The:[6,8,11,13,15,16,18],There:8,Using:7,With:[5,16],about:20,action:15,add:[2,11],adding:11,address:19,alphabet:5,altern:16,ana:13,analysi:6,anamorph:[2,13],app1:2,app2:2,app3:2,appendix:[11,13,18],appli:15,approxim:9,argument:18,auto:3,averag:2,base:[9,11],binari:[2,11,16],bliss:18,both:11,branch:[2,11,15],brzozowski:5,can:11,cata:13,catamorph:13,categor:4,chatter:2,check:17,child:11,choic:2,clear:2,cleav:[2,15],cmp:11,code:[8,11],combin:[2,11,13,18],comment:18,compact:5,compar:11,comparison:2,compil:[7,18],compile_:18,compos:18,comput:9,con:[2,18],concat:2,conclus:[13,18],consecut:9,continu:8,current:11,datastructur:[5,8,11,19],deal:18,defin:[11,16],definit:[12,15],delabel:18,delet:11,deriv:[5,12,13,16],design:13,determin:19,develop:6,diagram:5,dialect:0,dictionari:14,dip:[2,19],dipd:2,dipdd:2,direco:7,disenstacken:2,distinguish:18,div:2,doc_from_stack_effect:18,document:0,doe:11,down_to_zero:2,drive:5,drop:2,dup:[2,18],dupd:2,dupdip:2,effect:18,eleg:18,els:11,empti:11,enstacken:2,equal:11,essai:20,euler:[6,7],eval:8,even:7,exampl:[2,8,11,13,16,17],execut:22,explor:5,express:[5,8,21,24],extract:16,factori:13,fail:17,fibonacci:7,filter:6,find:[9,11,13],finish:15,finit:5,first:[2,6,15,18],five:7,flatten:2,flexibl:16,floordiv:2,formula:12,found:11,four:[13,15],fsm:5,fulmin:15,fun:13,fundament:15,further:6,gcd:2,gener:[3,5,6,7,9],genrec:2,get:[11,16],getitem:2,given:16,greater:11,group:2,handl:15,have:[11,16],help:2,highest:11,host:0,how:[6,7],hybrid:18,hylo:13,hylomorph:13,identifi:18,ift:[2,15],iii:18,implement:[5,18],indic:0,infer:[18,24],inferenc:18,inform:0,infra:[2,19],integ:6,interest:7,interlud:11,intern:21,interpret:[1,8,18],item:19,iter:[6,11],joi:[0,1,3,6,8,13,18,19,20,21,22,23,24],join:15,just:6,kei:11,kind:15,languag:0,larger:5,least_fract:2,left:11,less:11,let:[5,6],letter:5,librari:[3,8,18],like:11,list:[2,23],literari:8,littl:6,logic:[2,18],loop:[2,8,15],lower:11,lshift:2,machin:5,make:[7,9],mani:6,map:[2,15],match:5,math:2,memoiz:5,method:9,min:2,miscellan:2,mod:2,modifi:18,modulu:2,more:11,most:11,mul:[2,18],multipl:[6,7,18],must:11,name:12,neg:2,newton:9,next:9,node:11,non:11,now:11,nullari:2,nulli:5,number:[13,18],one:8,onli:8,oper:15,order:[11,16],osdn:0,other:15,our:11,out:5,over:2,pack:6,pam:[2,15],para:13,paradigm:18,parallel:15,parameter:[11,16],pars:[2,21],parser:[8,21],part:18,pass:8,path:19,pattern:13,per:11,polytyp:24,pop:[2,18],popd:2,popop:2,pow:2,power:7,pred:2,predic:[6,9,11,16],pretty_print:22,primit:13,primrec:2,print:8,problem:[6,7],process:11,product:2,program:[4,6,12,16,20],progress:18,project:[0,6,7],pure:8,put:[11,12,16],python:[8,14,18],quadrat:12,quick:0,quot:[2,23],rang:[2,6,13],range_to_zero:2,read:8,recur:[9,11],recurs:[11,13,16],redefin:[11,16],refactor:[6,11],refer:3,regular:[5,8],reimplement:16,relabel:18,rem:2,remaind:2,remov:2,render:6,repl:8,replac:[11,14],repres:[5,18],represent:5,reset:7,rest:[2,18],revers:[2,5,17],right:[11,19],rightmost:11,roll:[2,18],rolldown:2,rollup:2,rshift:2,rule:[5,18],run:[2,7],second:[2,18],select:2,sequenc:[7,15,18,23],set:[9,11],shorter:14,should:8,shunt:2,simpl:18,simplest:6,size:[2,14],sourc:11,special:[13,18],sqr:[2,18],sqrt:[2,12],stack:[2,8,18,23],start:0,state:5,step:[2,13,16],straightforward:12,stream:5,string:5,structur:11,style:8,sub:[2,11],subtyp:18,succ:2,sum:[2,6],swaack:2,swap:[2,18],swon:2,swoncat:2,symbol:[8,13],tabl:0,tail:13,take:2,term:[6,7,16],ternari:2,text:21,than:11,them:12,thi:11,third:[2,18],three:7,thun:[0,8],time:[2,7],togeth:[11,12,16],token:8,toler:9,trace:[14,22],traceprint:8,trampolin:5,travers:[11,16,19],treat:[11,16],tree:[11,16,19],treegrind:16,treestep:16,triangular:13,truediv:2,truthi:2,tuck:2,two:[5,7],type:[17,18,24],unari:2,unbound:18,uncon:[2,18],unif:17,unifi:18,unit:2,unnecessari:6,unquot:2,unstack:2,updat:[10,18],use:18,util:[22,23,24],valu:[7,11],variabl:12,variat:7,version:[6,11,14,18],view:8,vii:18,within:9,word:2,work:[17,18],write:12,xor:2,yin:18,zero:7,zip:2,zipper:19}}) \ No newline at end of file diff --git a/docs/sphinx_docs/_build/html/stack.html b/docs/sphinx_docs/_build/html/stack.html index 5329c20..ef59ae9 100644 --- a/docs/sphinx_docs/_build/html/stack.html +++ b/docs/sphinx_docs/_build/html/stack.html @@ -59,7 +59,7 @@ form of a stack with one or more items on it:

      means we can directly “unpack” the expected arguments to a Joy function.

      For example:

      def dup((head, tail)):
      -  return head, (head, tail)
      +        return head, (head, tail)
       

      We replace the argument “stack” by the expected structure of the stack, @@ -71,8 +71,8 @@ where they would be redundant.)

      web page, doesn’t handle tuples in the function parameters. And in Python 3, this syntax was removed entirely. Instead you would have to write:

      def dup(stack):
      -  head, tail = stack
      -  return head, (head, tail)
      +        head, tail = stack
      +        return head, (head, tail)
       

      We have two very simple functions, one to build up a stack from a Python @@ -168,21 +168,21 @@ won’t work because

      -joy.utils.stack.pick(s, n)[source]
      +joy.utils.stack.pick(stack, n)[source]

      Return the nth item on the stack.

      diff --git a/docs/sphinx_docs/_build/html/types.html b/docs/sphinx_docs/_build/html/types.html index d2335dc..13e9b34 100644 --- a/docs/sphinx_docs/_build/html/types.html +++ b/docs/sphinx_docs/_build/html/types.html @@ -117,6 +117,18 @@ +
      +
      +class joy.utils.types.CombinatorJoyType(name, sec, number, expect=None)[source]
      +

      Represent combinators.

      +

      These type variables carry Joy functions that implement the +behaviour of Joy combinators and they can appear in expressions. +For simple combinators the implementation functions can be the +combinators themselves.

      +

      These types can also specify a stack effect (input side only) to +guard against being used on invalid types.

      +
      +
      class joy.utils.types.FloatJoyType(number)[source]
      @@ -128,6 +140,11 @@
      +
      +
      +class joy.utils.types.FunctionJoyType(name, sec, number)[source]
      +
      +
      class joy.utils.types.IntJoyType(number)[source]
      @@ -144,6 +161,29 @@ exception joy.utils.types.JoyTypeError[source]
      +
      +
      +class joy.utils.types.KleeneStar(number)[source]
      +

      A sequence of zero or more AnyJoyType variables would be:

      +
      +
      A*
      +

      The A* works by splitting the universe into two alternate histories:

      +
      +

      A* → ∅

      +

      A* → A A*

      +
      +

      The Kleene star variable disappears in one universe, and in the other +it turns into an AnyJoyType variable followed by itself again.

      +

      We have to return all universes (represented by their substitution +dicts, the “unifiers”) that don’t lead to type conflicts.

      +
      +
      +kind
      +

      alias of AnyJoyType

      +
      + +
      +
      class joy.utils.types.NumberJoyType(number)[source]
      @@ -160,6 +200,25 @@
      +
      +
      +class joy.utils.types.SymbolJoyType(name, sec, number)[source]
      +

      Represent non-combinator functions.

      +

      These type variables carry the stack effect comments and can +appear in expressions (as in quoted programs.)

      +
      + +
      +
      +class joy.utils.types.TextJoyType(number)[source]
      +
      +
      +accept
      +

      alias of __builtin__.basestring

      +
      + +
      +
      joy.utils.types.compilable(f)[source]
      @@ -181,12 +240,6 @@ is used to generate one.

      Return the stack effect of the composition of some of stack effects.

      -
      -
      -joy.utils.types.defs()[source]
      -

      Return a dict of named stack effects.

      -
      -
      joy.utils.types.delabel(f, seen=None, c=None)[source]
      @@ -195,10 +248,40 @@ is used to generate one.

      -joy.utils.types.doc_from_stack_effect(inputs, outputs)[source]
      +joy.utils.types.doc_from_stack_effect(inputs, outputs=('??', ()))[source]

      Return a crude string representation of a stack effect.

      +
      +
      +joy.utils.types.infer(*expression)[source]
      +

      Return a list of stack effects for a Joy expression.

      +

      For example:

      +
      h = infer(pop, swap, rolldown, rest, rest, cons, cons)
      +for fi, fo in h:
      +                print doc_from_stack_effect(fi, fo)
      +
      +
      +

      Prints:

      +
      ([a4 a5 ...1] a3 a2 a1 -- [a2 a3 ...1])
      +
      +
      +
      + +
      +
      +joy.utils.types.meta_compose(F, G, e)[source]
      +

      Yield the stack effects of the composition of two lists of stack +effects. An expression is carried along and updated and yielded.

      +
      + +
      +
      +joy.utils.types.poly_compose(f, g, e)[source]
      +

      Yield the stack effects of the composition of two stack effects. An +expression is carried along and updated and yielded.

      +
      +
      joy.utils.types.reify(meaning, name, seen=None)[source]
      @@ -212,8 +295,16 @@ is used to generate one.

      -
      -joy.utils.types.unify(u, v, s=None)[source]
      +
      +joy.utils.types.type_check(name, stack)[source]
      +

      Trinary predicate. True if named function type-checks, False if it +fails, None if it’s indeterminate (because I haven’t entered it into +the FUNCTIONS dict yet.)

      +
      + +
      +
      +joy.utils.types.uni_unify(u, v, s=None)[source]

      Return a substitution dict representing a unifier for u and v.

      @@ -272,114 +363,6 @@ is used to generate one.

      (i2 i1 -- i3) -

      Multiple Stack Effects

      -

      By adjusting the machinery in types.py to handles lists of stack effect comments -we can capture more information about the type signatures of some functions, -and we can introduce a kind of Kleene Star or sequence type that can stand for -an unbounded sequence of other types.

      -
      -
      -class joy.utils.polytypes.CombinatorJoyType(name, sec, number, expect=None)[source]
      -

      Represent combinators.

      -

      These type variables carry Joy functions that implement the -behaviour of Joy combinators and they can appear in expressions. -For simple combinators the implementation functions can be the -combinators themselves.

      -

      These types can also specify a stack effect (input side only) to -guard against being used on invalid types.

      -
      - -
      -
      -joy.utils.polytypes.FUNCTIONS = {'!=': ne, '&': and, '*': mul, '+': add, '++': succ, '-': sub, '--': pred, '/': truediv, '<': lt, '<<': lshift, '<=': le, '<>': ne, '=': eq, '>': gt, '>=': ge, '>>': rshift, '_Tree_add_Ee': _Tree_add_Ee, '_Tree_delete_R0': _Tree_delete_R0, '_Tree_delete_clear_stuff': _Tree_delete_clear_stuff, '_Tree_get_E': _Tree_get_E, 'add': add, 'and': and, 'b': b, 'bool': bool, 'branch': branch, 'ccons': ccons, 'clear': clear, 'concat_': concat_, 'cons': cons, 'dip': dip, 'dipd': dipd, 'dipdd': dipdd, 'div': div, 'divmod': divmod, 'dup': dup, 'dupd': dupd, 'dupdd': dupdd, 'dupdip': dupdip, 'eq': eq, 'first': first, 'first_two': first_two, 'floordiv': floordiv, 'fourth': fourth, 'ge': ge, 'gt': gt, 'i': i, 'infra': infra, 'le': le, 'loop': loop, 'lshift': lshift, 'lt': lt, 'modulus': modulus, 'mul': mul, 'ne': ne, 'neg': neg, 'not': not, 'nullary': nullary, 'over': over, 'pop': pop, 'popd': popd, 'popdd': popdd, 'popop': popop, 'popopd': popopd, 'popopdd': popopdd, 'pow': pow, 'pred': pred, 'product': product, 'rest': rest, 'roll<': rolldown, 'roll>': rollup, 'rolldown': rolldown, 'rollup': rollup, 'rrest': rrest, 'rshift': rshift, 'second': second, 'sqrt': sqrt, 'stack': stack, 'stuncons': stuncons, 'stununcons': stununcons, 'sub': sub, 'succ': succ, 'sum': sum, 'swaack': swaack, 'swap': swap, 'swons': swons, 'third': third, 'truediv': truediv, 'truthy': bool, 'tuck': tuck, 'uncons': uncons, 'unit': unit, 'unswons': unswons, 'x': x}
      -

      Docstring for functions in Sphinx?

      -
      - -
      -
      -class joy.utils.polytypes.FunctionJoyType(name, sec, number)[source]
      -
      - -
      -
      -class joy.utils.polytypes.IntJoyType(number)[source]
      -
      - -
      -
      -class joy.utils.polytypes.KleeneStar(number)[source]
      -

      A sequence of zero or more AnyJoyType variables would be:

      -
      -
      A*
      -

      The A* works by splitting the universe into two alternate histories:

      -
      -

      A* → ∅

      -

      A* → A A*

      -
      -

      The Kleene star variable disappears in one universe, and in the other -it turns into an AnyJoyType variable followed by itself again.

      -

      We have to return all universes (represented by their substitution -dicts, the “unifiers”) that don’t lead to type conflicts.

      -
      -
      -kind
      -

      alias of joy.utils.types.AnyJoyType

      -
      - -
      - -
      -
      -class joy.utils.polytypes.SymbolJoyType(name, sec, number)[source]
      -

      Represent non-combinator functions.

      -

      These type variables carry the stack effect comments and can -appear in expressions (as in quoted programs.)

      -
      - -
      -
      -joy.utils.polytypes.compose(f, g, e)[source]
      -

      Yield the stack effects of the composition of two stack effects. An -expression is carried along and updated and yielded.

      -
      - -
      -
      -joy.utils.polytypes.defs()[source]
      -

      Return a dict of FunctionJoyType instances to be used with infer().

      -
      - -
      -
      -joy.utils.polytypes.infer(*expression)[source]
      -

      Return a list of stack effects for a Joy expression.

      -

      For example:

      -
      h = infer(pop, swap, rolldown, rest, rest, cons, cons)
      -for fi, fo in h:
      -    print doc_from_stack_effect(fi, fo)
      -
      -
      -

      Prints:

      -
      ([a4 a5 ...1] a3 a2 a1 -- [a2 a3 ...1])
      -
      -
      -
      - -
      -
      -joy.utils.polytypes.meta_compose(F, G, e)[source]
      -

      Yield the stack effects of the composition of two lists of stack -effects. An expression is carried along and updated and yielded.

      -
      - -
      -
      -joy.utils.polytypes.type_check(name, stack)[source]
      -

      Trinary predicate. True if named function type-checks, False if it -fails, None if it’s indeterminate (because I haven’t entered it into -the FUNCTIONS dict yet.)

      -
      -
      Parameters:
        -
      • s (stack) – A stack.
      • +
      • stack (stack) – A stack.
      • n (int) – An index into the stack.
      Raises:
      • ValueError – if n is less than zero.
      • -
      • IndexError – if n is equal to or greater than the length of s.
      • +
      • IndexError – if n is equal to or greater than the length of stack.