diff --git a/docs/0._This_Implementation_of_Joy_in_Python.html b/docs/0._This_Implementation_of_Joy_in_Python.html index 6bb8ac8..0a4a6eb 100644 --- a/docs/0._This_Implementation_of_Joy_in_Python.html +++ b/docs/0._This_Implementation_of_Joy_in_Python.html @@ -11854,57 +11854,56 @@ joy?
@@ -12079,22 +12078,36 @@ where they would be redundant. @@ -12163,19 +12176,22 @@ where they would be redundant. @@ -12216,27 +12232,27 @@ Any unbalanced square brackets will raise a ParseError. @@ -12455,7 +12471,7 @@ Any unbalanced square brackets will raise a ParseError. @@ -12495,10 +12511,24 @@ Any unbalanced square brackets will raise a ParseError. @@ -12539,28 +12569,26 @@ Any unbalanced square brackets will raise a ParseError. diff --git a/docs/0._This_Implementation_of_Joy_in_Python.md b/docs/0._This_Implementation_of_Joy_in_Python.md index 1e0b8b9..cc61da8 100644 --- a/docs/0._This_Implementation_of_Joy_in_Python.md +++ b/docs/0._This_Implementation_of_Joy_in_Python.md @@ -52,57 +52,56 @@ import joy.utils.stack print inspect.getdoc(joy.utils.stack) ``` - § Stack + When talking about Joy we use the terms "stack", "quote", "sequence", + "list", and others to mean the same thing: a simple linear datatype that + permits certain operations such as iterating and pushing and popping + values from (at least) one end. + 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 recursive + form of a stack with one or more items on it:: - When talking about Joy we use the terms "stack", "list", "sequence" and - "aggregate" to mean the same thing: a simple datatype that permits - certain operations such as iterating and pushing and popping values from - (at least) one end. + stack := () | (item, stack) - We use the venerable two-tuple recursive form of sequences where the - empty tuple () is the empty stack and (head, rest) gives the recursive - form of a stack with one or more items on it. + Putting some numbers onto a stack:: - () - (1, ()) - (2, (1, ())) - (3, (2, (1, ()))) - ... - - And so on. - - - We have two very simple functions to build up a stack from a Python - iterable and also to iterate through a stack and yield its items - one-by-one in order, and two functions to generate string representations - of stacks: - - list_to_stack() - - iter_stack() - - expression_to_string() (prints left-to-right) - - stack_to_string() (prints right-to-left) - - - A word about the stack data structure. + () + (1, ()) + (2, (1, ())) + (3, (2, (1, ()))) + ... Python has very nice "tuple packing and unpacking" in its syntax which means we can directly "unpack" the expected arguments to a Joy function. - For example: + For example:: - def dup(stack): - head, tail = stack - 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 de-structuring the - incoming argument and assigning values to the names. Note that Python + in this case "(head, tail)", and Python takes care of unpacking the + incoming tuple and assigning values to the names. (Note that Python syntax doesn't require parentheses around tuples used in expressions - where they would be redundant. + where they would be redundant.) + + Unfortunately, the Sphinx documentation generator, which is used to generate this + 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) + + + 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 + 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`. + + .. _cons list: https://en.wikipedia.org/wiki/Cons#Lists ### The utility functions maintain order. @@ -166,22 +165,36 @@ print inspect.getsource(joy.joy.joy) ``` def joy(stack, expression, dictionary, viewer=None): - ''' - Evaluate the Joy expression on the stack. - ''' - while expression: + '''Evaluate a Joy expression on a stack. - if viewer: viewer(stack, expression) + 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. - term, expression = expression - if isinstance(term, Symbol): - term = dictionary[term] - stack, expression, dictionary = term(stack, expression, dictionary) - else: - stack = term, stack + 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) - return stack, expression, dictionary + :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) + + ''' + while expression: + + 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 @@ -204,19 +217,22 @@ import joy.parser print inspect.getdoc(joy.parser) ``` - § Converting text to a joy expression. + This module exports a single function for converting text to a joy + expression as well as a single Symbol class and a single Exception type. - This module exports a single function: + The Symbol string class is used by the interpreter to recognize literals + by the fact that they are not Symbol objects. - text_to_expression(text) + A crude grammar:: - As well as a single Symbol class and a single Exception type: + joy = term* + term = int | float | string | '[' joy ']' | symbol - 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. + 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. The parser is extremely simple, the undocumented `re.Scanner` class does most of the tokenizing work and then you just build the tuple structure out of the tokens. There's no Abstract Syntax Tree or anything like that. @@ -227,27 +243,27 @@ print inspect.getsource(joy.parser._parse) ``` 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('One or more extra closing brackets.') - frame[-1] = list_to_stack(frame[-1]) - else: - frame.append(tok) - if stack: - raise ParseError('One or more unclosed brackets.') - 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) @@ -325,7 +341,7 @@ import joy.library print ' '.join(sorted(joy.library.initialize())) ``` - != % & * *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 • + != % & * *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 • Many of the functions are defined in Python, like `dip`: @@ -335,10 +351,24 @@ Many of the functions are defined in Python, like `dip`: print inspect.getsource(joy.library.dip) ``` + @inscribe + @combinator_effect(_COMB_NUMS(), a1, s1) + @FunctionWrapper def dip(stack, expression, dictionary): - (quote, (x, stack)) = stack - expression = x, expression - return stack, pushback(quote, 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. + :: + + ... x [Q] dip + ------------------- + ... Q x + + ''' + (quote, (x, stack)) = stack + expression = (x, expression) + return stack, concat(quote, expression), dictionary @@ -349,28 +379,26 @@ Some functions are defined in equations in terms of other functions. When the i print joy.library.definitions ``` - second == rest first - third == rest rest first + ii == [dip] dupdip i + of == swap at product == 1 swap [*] step - swons == swap cons - swoncat == swap concat flatten == [] swap [concat] step - unit == [] cons 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 == [stack [pop] dip] dinfrirst - binary == [stack [popop] dip] dinfrirst - ternary == [stack [popop pop] dip] dinfrirst + unary == nullary popd + binary == nullary [popop] dip + ternary == unary [popop] dip pam == [i] map run == [] swap infra sqr == dup mul size == 0 swap [pop ++] step - cleave == [i] app2 [popd] dip + 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 @@ -381,8 +409,12 @@ print joy.library.definitions anamorphism == [pop []] swap [dip swons] genrec range == [0 <=] [1 - dup] anamorphism while == swap [nullary] cons dup dipd concat loop - dudipd == dup dipd + 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/0._This_Implementation_of_Joy_in_Python.rst b/docs/0._This_Implementation_of_Joy_in_Python.rst index 7515dcc..60b736c 100644 --- a/docs/0._This_Implementation_of_Joy_in_Python.rst +++ b/docs/0._This_Implementation_of_Joy_in_Python.rst @@ -77,57 +77,56 @@ tuples. .. parsed-literal:: - § Stack + When talking about Joy we use the terms "stack", "quote", "sequence", + "list", and others to mean the same thing: a simple linear datatype that + permits certain operations such as iterating and pushing and popping + values from (at least) one end. + 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 recursive + form of a stack with one or more items on it:: - When talking about Joy we use the terms "stack", "list", "sequence" and - "aggregate" to mean the same thing: a simple datatype that permits - certain operations such as iterating and pushing and popping values from - (at least) one end. + stack := () | (item, stack) - We use the venerable two-tuple recursive form of sequences where the - empty tuple () is the empty stack and (head, rest) gives the recursive - form of a stack with one or more items on it. + Putting some numbers onto a stack:: - () - (1, ()) - (2, (1, ())) - (3, (2, (1, ()))) - ... - - And so on. - - - We have two very simple functions to build up a stack from a Python - iterable and also to iterate through a stack and yield its items - one-by-one in order, and two functions to generate string representations - of stacks: - - list_to_stack() - - iter_stack() - - expression_to_string() (prints left-to-right) - - stack_to_string() (prints right-to-left) - - - A word about the stack data structure. + () + (1, ()) + (2, (1, ())) + (3, (2, (1, ()))) + ... Python has very nice "tuple packing and unpacking" in its syntax which means we can directly "unpack" the expected arguments to a Joy function. - For example: + For example:: - def dup(stack): - head, tail = stack - 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 de-structuring the - incoming argument and assigning values to the names. Note that Python + in this case "(head, tail)", and Python takes care of unpacking the + incoming tuple and assigning values to the names. (Note that Python syntax doesn't require parentheses around tuples used in expressions - where they would be redundant. + where they would be redundant.) + + Unfortunately, the Sphinx documentation generator, which is used to generate this + 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) + + + 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 + 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`. + + .. _cons list: https://en.wikipedia.org/wiki/Cons#Lists The utility functions maintain order. @@ -216,22 +215,36 @@ command.) .. parsed-literal:: def joy(stack, expression, dictionary, viewer=None): - ''' - Evaluate the Joy expression on the stack. - ''' - while expression: + '''Evaluate a Joy expression on a stack. - if viewer: viewer(stack, expression) + 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. - term, expression = expression - if isinstance(term, Symbol): - term = dictionary[term] - stack, expression, dictionary = term(stack, expression, dictionary) - else: - stack = term, stack + 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) - return stack, expression, dictionary + :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) + + ''' + while expression: + + 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 @@ -276,19 +289,22 @@ Parser .. parsed-literal:: - § Converting text to a joy expression. + This module exports a single function for converting text to a joy + expression as well as a single Symbol class and a single Exception type. - This module exports a single function: + The Symbol string class is used by the interpreter to recognize literals + by the fact that they are not Symbol objects. - text_to_expression(text) + A crude grammar:: - As well as a single Symbol class and a single Exception type: + joy = term* + term = int | float | string | '[' joy ']' | symbol - 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. + 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. The parser is extremely simple, the undocumented ``re.Scanner`` class @@ -304,27 +320,27 @@ like that. .. parsed-literal:: 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('One or more extra closing brackets.') - frame[-1] = list_to_stack(frame[-1]) - else: - frame.append(tok) - if stack: - raise ParseError('One or more unclosed brackets.') - 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) @@ -415,7 +431,7 @@ provide control-flow and higher-order operations. .. parsed-literal:: - != % & * *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 • + != % & * *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 • Many of the functions are defined in Python, like ``dip``: @@ -427,10 +443,24 @@ Many of the functions are defined in Python, like ``dip``: .. parsed-literal:: + @inscribe + @combinator_effect(_COMB_NUMS(), a1, s1) + @FunctionWrapper def dip(stack, expression, dictionary): - (quote, (x, stack)) = stack - expression = x, expression - return stack, pushback(quote, 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. + :: + + ... x [Q] dip + ------------------- + ... Q x + + ''' + (quote, (x, stack)) = stack + expression = (x, expression) + return stack, concat(quote, expression), dictionary @@ -446,28 +476,26 @@ continuation) and returns control to the interpreter. .. parsed-literal:: - second == rest first - third == rest rest first + ii == [dip] dupdip i + of == swap at product == 1 swap [*] step - swons == swap cons - swoncat == swap concat flatten == [] swap [concat] step - unit == [] cons 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 == [stack [pop] dip] dinfrirst - binary == [stack [popop] dip] dinfrirst - ternary == [stack [popop pop] dip] dinfrirst + unary == nullary popd + binary == nullary [popop] dip + ternary == unary [popop] dip pam == [i] map run == [] swap infra sqr == dup mul size == 0 swap [pop ++] step - cleave == [i] app2 [popd] dip + 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 @@ -478,8 +506,12 @@ continuation) and returns control to the interpreter. anamorphism == [pop []] swap [dip swons] genrec range == [0 <=] [1 - dup] anamorphism while == swap [nullary] cons dup dipd concat loop - dudipd == dup dipd + 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/2._Library_Examples.html b/docs/2._Library_Examples.html index 62c49ae..2e3a9e5 100644 --- a/docs/2._Library_Examples.html +++ b/docs/2._Library_Examples.html @@ -12535,9 +12535,35 @@ div#notebook { - @@ -12547,7 +12573,7 @@ div#notebook {J('[1 2 3] [4 5 6] shunt')
@@ -12557,24 +12583,6 @@ div#notebook {
J('1 [2 3] cons')
@@ -12596,28 +12604,10 @@ div#notebook {
J('[2 3] 1 swons')
@@ -12627,28 +12617,10 @@ div#notebook {
J('[1 2 3] uncons')
@@ -12658,24 +12630,6 @@ div#notebook {
J('[1 2 3 4] first')
@@ -12697,28 +12651,10 @@ div#notebook {
J('[1 2 3 4] second')
@@ -12728,28 +12664,10 @@ div#notebook {
J('[1 2 3 4] third')
@@ -12759,28 +12677,10 @@ div#notebook {
J('[1 2 3 4] rest')
@@ -12790,24 +12690,6 @@ div#notebook {
J('[[1] [2 [3] 4] [5 6]] flatten')
@@ -12829,24 +12711,6 @@ div#notebook {
J('[10 11 12 13 14] 2 getitem')
@@ -12869,28 +12733,10 @@ div#notebook {
J('[1 2 3 4] 0 at')
@@ -12900,28 +12746,10 @@ div#notebook {
J('2 [1 2 3 4] of')
@@ -12931,28 +12759,10 @@ div#notebook {
J('[1 2 3 4] 2 drop')
@@ -12962,28 +12772,10 @@ div#notebook {
J('[1 2 3 4] 2 take') # reverses the order
@@ -12993,24 +12785,6 @@ div#notebook {
J('[1 2 3 1 4] 1 remove')
@@ -13041,24 +12815,6 @@ div#notebook {
J('[1 2 3 4] reverse')
@@ -13080,24 +12836,6 @@ div#notebook {
J('[1 1 1 1] size')
@@ -13119,24 +12857,6 @@ div#notebook {
J('1 2 3 [4 5 6] swaack')
@@ -13159,24 +12879,6 @@ div#notebook {
J('23 9 1 choice')
@@ -13198,28 +12900,10 @@ div#notebook {
J('23 9 0 choice')
@@ -13229,28 +12913,10 @@ div#notebook {
J('[23 9 7] 1 select') # select is basically getitem, should retire it?
@@ -13260,28 +12926,10 @@ div#notebook {
J('[23 9 7] 0 select')
@@ -13291,24 +12939,6 @@ div#notebook {
J('[1 2 3] [6 5 4] zip')
@@ -13330,28 +12960,10 @@ div#notebook {
J('[1 2 3] [6 5 4] zip [sum] map')
@@ -13361,24 +12973,6 @@ div#notebook {
J('23 9 +')
@@ -13408,24 +13002,6 @@ div#notebook {
J('23 9 -')
@@ -13447,24 +13023,6 @@ div#notebook {
J('23 9 *')
@@ -13486,24 +13044,6 @@ div#notebook {
J('23 9 /')
@@ -13525,28 +13065,10 @@ div#notebook {
J('23 -9 truediv')
@@ -13556,28 +13078,10 @@ div#notebook {
J('23 9 div')
@@ -13587,28 +13091,10 @@ div#notebook {
J('23 9 floordiv')
@@ -13618,28 +13104,10 @@ div#notebook {
J('23 -9 div')
@@ -13649,28 +13117,10 @@ div#notebook {
J('23 -9 floordiv')
@@ -13680,24 +13130,6 @@ div#notebook {
J('23 9 %')
@@ -13719,24 +13151,6 @@ div#notebook {
J('23 neg -5 neg')
@@ -13758,24 +13172,6 @@ div#notebook {
J('2 10 pow')
@@ -13797,24 +13193,6 @@ div#notebook {
J('23 sqr')
@@ -13836,28 +13214,10 @@ div#notebook {
J('23 sqrt')
@@ -13867,24 +13227,6 @@ div#notebook {
J('1 ++')
@@ -13906,28 +13248,10 @@ div#notebook {
J('1 --')
@@ -13937,24 +13261,6 @@ div#notebook {
J('8 1 <<')
@@ -13976,28 +13282,10 @@ div#notebook {
J('8 1 >>')
@@ -14007,24 +13295,6 @@ div#notebook {
J('[1 2 3 5] average')
@@ -14046,24 +13316,6 @@ div#notebook {
J('5 range')
@@ -14085,28 +13337,10 @@ div#notebook {
J('5 range_to_zero')
@@ -14116,28 +13350,10 @@ div#notebook {
J('5 down_to_zero')
@@ -14147,24 +13363,6 @@ div#notebook {
J('[1 2 3 5] product')
@@ -14186,24 +13384,6 @@ div#notebook {
J('[1 2 3 5] sum')
@@ -14225,24 +13405,6 @@ div#notebook {
J('[1 2 3 5] min')
@@ -14264,24 +13426,6 @@ div#notebook {
J('45 30 gcd')
@@ -14303,24 +13447,6 @@ div#notebook {
J('[45 30] least_fraction')
@@ -14343,28 +13469,10 @@ div#notebook {
J('[23 12] least_fraction')
@@ -14374,24 +13482,6 @@ div#notebook {
J('23 truthy')
@@ -14422,28 +13512,10 @@ div#notebook {
J('[] truthy') # Python semantics.
@@ -14453,28 +13525,10 @@ div#notebook {
J('0 truthy')
@@ -14484,24 +13538,6 @@ div#notebook {
V('23 ?')
@@ -14525,32 +13561,10 @@ div#notebook {
J('[] ?')
@@ -14560,28 +13574,10 @@ div#notebook {
J('0 ?')
@@ -14591,24 +13587,6 @@ div#notebook {
J('23 9 &')
@@ -14630,24 +13608,6 @@ div#notebook {
J('23 9 !=')
@@ -14669,24 +13629,6 @@ div#notebook {
J('1 1 ^')
@@ -14726,28 +13668,10 @@ div#notebook {
J('1 0 ^')
@@ -14757,24 +13681,6 @@ div#notebook {
J('[help] help')
@@ -14804,25 +13710,6 @@ div#notebook {
J('[parse] help')
@@ -14844,29 +13731,10 @@ div#notebook {
J('1 "2 [3] dup" parse')
@@ -14876,24 +13744,6 @@ div#notebook {
J('[1 2 dup + +] run')
@@ -14916,24 +13766,6 @@ div#notebook {
J('[app1] help')
@@ -14963,35 +13795,10 @@ div#notebook {
J('10 4 [sqr *] app1')
@@ -15001,28 +13808,10 @@ program.
J('10 3 4 [sqr *] app2')
@@ -15032,28 +13821,10 @@ program.
J('[app2] help')
@@ -15063,34 +13834,10 @@ program.
J('10 2 3 4 [sqr *] app3')
@@ -15100,24 +13847,6 @@ program.
J('3 [0 <=] [1 - dup] anamorphism')
@@ -15149,24 +13878,6 @@ program.
J('3 4 1 [+] [*] branch')
@@ -15188,28 +13899,10 @@ program.
J('3 4 0 [+] [*] branch')
@@ -15219,24 +13912,6 @@ program.
J('10 2 [+] [-] cleave')
@@ -15270,24 +13945,6 @@ results P(X) and Q(X)."
J('1 2 3 4 5 [+] dip')
@@ -15309,28 +13966,10 @@ results P(X) and Q(X)."
J('1 2 3 4 5 [+] dipd')
@@ -15340,28 +13979,10 @@ results P(X) and Q(X)."
J('1 2 3 4 5 [+] dipdd')
@@ -15371,24 +13992,6 @@ results P(X) and Q(X)."
V('23 [++] dupdip *') # N(N + 1)
@@ -15413,30 +14016,6 @@ results P(X) and Q(X)."
J('[genrec] help')
@@ -15458,72 +14037,10 @@ results P(X) and Q(X)."
J('3 [1 <=] [] [dup --] [i *] genrec')
@@ -15533,24 +14050,6 @@ the original definition in the else-part:
V('1 2 3 [+ +] i')
@@ -15572,31 +14071,6 @@ the original definition in the else-part:
J('1 2 [1] [+] [*] ifte')
@@ -15620,28 +14094,10 @@ the original definition in the else-part:
J('1 2 [0] [+] [*] ifte')
@@ -15651,24 +14107,6 @@ the original definition in the else-part:
V('1 2 3 [4 5 6] [* +] infra')
@@ -15690,34 +14128,6 @@ the original definition in the else-part:
J('[loop] help')
@@ -15739,37 +14149,10 @@ the original definition in the else-part:
V('3 dup [1 - dup] loop')
@@ -15779,43 +14162,6 @@ the original definition in the else-part:
J('10 [1 2 3] [*] map')
@@ -15837,28 +14183,10 @@ the original definition in the else-part:
J('10 5 [[*][/][+][-]] pam')
@@ -15868,24 +14196,6 @@ the original definition in the else-part:
J('1 2 3 4 5 [+] nullary')
@@ -15908,28 +14218,10 @@ the original definition in the else-part:
J('1 2 3 4 5 [+] unary')
@@ -15939,28 +14231,10 @@ the original definition in the else-part:
J('1 2 3 4 5 [+] binary') # + has arity 2 so this is technically pointless...
@@ -15970,28 +14244,10 @@ the original definition in the else-part:
J('1 2 3 4 5 [+] ternary')
@@ -16001,24 +14257,6 @@ the original definition in the else-part:
J('[step] help')
@@ -16040,46 +14278,10 @@ the original definition in the else-part:
V('0 [1 2 3] [+] step')
@@ -16089,40 +14291,6 @@ on top of the stack.
V('3 2 1 2 [+] times')
@@ -16144,35 +14312,6 @@ on top of the stack.
J('[b] help')
@@ -16194,32 +14333,10 @@ on top of the stack.
V('1 2 [3] [4] b')
@@ -16229,31 +14346,6 @@ on top of the stack.
J('3 [0 >] [dup --] while')
@@ -16277,24 +14369,6 @@ on top of the stack.
J('[x] help')
@@ -16316,33 +14390,10 @@ on top of the stack.
V('1 [2] [i 3] x') # Kind of a pointless example.
@@ -16352,33 +14403,6 @@ on top of the stack.
J('[] void')
@@ -16401,28 +14425,10 @@ on top of the stack.
J('[[]] void')
@@ -16432,28 +14438,10 @@ on top of the stack.
J('[[][[]]] void')
@@ -16463,28 +14451,10 @@ on top of the stack.
J('[[[]][[][]]] void')
@@ -16494,24 +14464,6 @@ on top of the stack.
from notebook_preamble import D, J, V, define, DefinitionWrapper
@@ -13008,11 +13008,11 @@ E == pop swap roll< rest rest cons cons
from joy.library import FunctionWrapper
-from joy.utils.stack import pushback
+from joy.utils.stack import concat
from notebook_preamble import D
@@ -13035,7 +13035,7 @@ E == pop swap roll< rest rest cons cons
L
'''
L, (E, (G, (b, (a, stack)))) = stack
- expression = pushback(G if a > b else L if a < b else E, expression)
+ expression = concat(G if a > b else L if a < b else E, expression)
return stack, expression, dictionary
@@ -13049,7 +13049,7 @@ E == pop swap roll< rest rest cons cons
from joy.library import FunctionWrapper, S_ifte
@@ -13102,7 +13102,7 @@ E == pop swap roll< rest rest cons cons
J("1 0 ['G'] ['E'] ['L'] cmp")
@@ -13133,7 +13133,7 @@ E == pop swap roll< rest rest cons cons
J("1 1 ['G'] ['E'] ['L'] cmp")
@@ -13164,7 +13164,7 @@ E == pop swap roll< rest rest cons cons
J("0 1 ['G'] ['E'] ['L'] cmp")
@@ -13195,7 +13195,7 @@ E == pop swap roll< rest rest cons cons
from joy.library import DefinitionWrapper
@@ -13220,7 +13220,7 @@ E == pop swap roll< rest rest cons cons
J('[] 23 "b" BTree-add') # Initial
@@ -13251,7 +13251,7 @@ E == pop swap roll< rest rest cons cons
J('["b" 23 [] []] 88 "c" BTree-add') # Less than
@@ -13282,7 +13282,7 @@ E == pop swap roll< rest rest cons cons
J('["b" 23 [] []] 88 "a" BTree-add') # Greater than
@@ -13313,7 +13313,7 @@ E == pop swap roll< rest rest cons cons
J('["b" 23 [] []] 88 "b" BTree-add') # Equal to
@@ -13344,7 +13344,7 @@ E == pop swap roll< rest rest cons cons