diff --git a/docs/sphinx_docs/lib.rst b/docs/sphinx_docs/lib.rst index 2b93e4f..e341820 100644 --- a/docs/sphinx_docs/lib.rst +++ b/docs/sphinx_docs/lib.rst @@ -473,7 +473,7 @@ List words "Swap stack" swap the list on the top of the stack for the stack, and put the old stack on top of the new one. Think of it as a context -switch. Niether of the lists/stacks change their order. +switch. Neither of the lists/stacks change their order. .. code:: python diff --git a/docs/sphinx_docs/notebooks/The_Four_Operations.rst b/docs/sphinx_docs/notebooks/The_Four_Operations.rst index b345b0e..2dc77d3 100644 --- a/docs/sphinx_docs/notebooks/The_Four_Operations.rst +++ b/docs/sphinx_docs/notebooks/The_Four_Operations.rst @@ -316,7 +316,7 @@ The other sub-programs would be cancelled. “Fulminators” ^^^^^^^^^^^^^ -Also known as “Futures” or “Promises” (by *everybody* else. “Fulinators” +Also known as “Futures” or “Promises” (by *everybody* else. “Fulminators” is what I was going to call them when I was thinking about implementing them in Thun.) diff --git a/implementations/Python/joy/joy.py b/implementations/Python/joy/joy.py index eb2674c..76fc8f9 100644 --- a/implementations/Python/joy/joy.py +++ b/implementations/Python/joy/joy.py @@ -25,9 +25,9 @@ match the behaviour of the original version(s) written in C. ''' from builtins import input from traceback import print_exc -from .parser import text_to_expression, ParseError, Symbol -from .utils.stack import stack_to_string -from .utils.errors import ( +from joy.parser import text_to_expression, ParseError, Symbol +from joy.utils.stack import stack_to_string +from joy.utils.errors import ( NotAListError, NotAnIntError, StackUnderflowError, @@ -38,12 +38,13 @@ class UnknownSymbolError(KeyError): pass def joy(stack, expression, dictionary, viewer=None): - '''Evaluate a Joy expression on a stack. + ''' + 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 - dictionary and executed. + 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 + dictionary 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/implementations/Python/joy/parser.py b/implementations/Python/joy/parser.py index 2c3ae53..3e31a80 100644 --- a/implementations/Python/joy/parser.py +++ b/implementations/Python/joy/parser.py @@ -27,18 +27,18 @@ by the fact that they are not Symbol objects. A crude grammar:: joy = term* - term = int | float | string | '[' joy ']' | symbol + term = integer | '[' 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 +literal value (integer or Joy expression) or a function symbol. +Function symbols are sequences of non-blanks and cannot contain square brackets. Terms must be separated by blanks, which can be omitted around square brackets. ''' from re import Scanner -from .utils.stack import list_to_stack -from .utils.snippets import ( +from joy.utils.stack import list_to_stack +from joy.utils.snippets import ( pat as SNIPPETS, from_string, Snippet, diff --git a/implementations/Python/joy/utils/stack.py b/implementations/Python/joy/utils/stack.py index 90f75fd..48223eb 100644 --- a/implementations/Python/joy/utils/stack.py +++ b/implementations/Python/joy/utils/stack.py @@ -23,6 +23,19 @@ When talking about Joy we use the terms "stack", "quote", "sequence", permits certain operations such as iterating and pushing and popping values from (at least) one end. +> In describing Joy I have used the term quotation to describe all of the +above, because I needed a word to describe the arguments to combinators +which fulfill the same role in Joy as lambda abstractions (with +variables) fulfill in the more familiar functional languages. I use the +term list for those quotations whose members are what I call literals: +numbers, characters, truth values, sets, strings and other quotations. +All these I call literals because their occurrence in code results in +them being pushed onto the stack. But I also call [London Paris] a list. +So, [dup *] is a quotation but not a list. + +"A Conversation with Manfred von Thun" w/ Stevan Apter +http://archive.vector.org.uk/art10000350 + There is no "Stack" Python class, instead we use the `cons list`_, a venerable two-tuple recursive sequence datastructure, where the empty tuple ``()`` is the empty stack and ``(head, rest)`` gives the @@ -62,7 +75,7 @@ syntax was removed entirely. Instead you would have to write:: We have two very simple functions, one to build up a stack from a Python -iterable and another to iterate through a stack and yield its items +list and another to iterate through a stack and yield its items one-by-one in order. There are also two functions to generate string representations 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 printed left-to-right. These functions are written to support :doc:`../pretty`. @@ -81,7 +94,9 @@ def list_to_stack(el, 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. + :param stack stack: A stack, optional, defaults to the empty stack. This + allows for concatinating Python lists (or other sequence objects) + onto an existing Joy stack. :rtype: stack ''' @@ -163,12 +178,12 @@ def concat(quote, expression): :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(). + # :raises RuntimeError: if quote is larger than sys.getrecursionlimit(). ## return (quote[0], concat(quote[1], expression)) if quote else expression diff --git a/implementations/defs.txt b/implementations/defs.txt index 2af30ef..570293f 100644 --- a/implementations/defs.txt +++ b/implementations/defs.txt @@ -21,6 +21,7 @@ ccons cons cons clear [] swaack pop cleave fork popdd clop cleave popdd +cmp [[>] swap] dipd [ifte] ccons [=] swons ifte codi cons dip codireco codi reco dinfrirst dip infrst