Rebuilt some sphinx docs.
This commit is contained in:
parent
ff6d427b2f
commit
d7d6114963
|
|
@ -11854,57 +11854,56 @@ joy? </code></pre>
|
|||
|
||||
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
<pre>§ Stack
|
||||
<pre>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
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -12079,22 +12078,36 @@ where they would be redundant.
|
|||
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
<pre>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
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -12163,19 +12176,22 @@ where they would be redundant.
|
|||
|
||||
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
<pre>§ Converting text to a joy expression.
|
||||
<pre>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.
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -12216,27 +12232,27 @@ Any unbalanced square brackets will raise a ParseError.
|
|||
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
<pre>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)
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -12455,7 +12471,7 @@ Any unbalanced square brackets will raise a ParseError.
|
|||
|
||||
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
<pre>!= % & * *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 •
|
||||
<pre>!= % & * *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 •
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -12495,10 +12511,24 @@ Any unbalanced square brackets will raise a ParseError.
|
|||
|
||||
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
<pre>def dip(stack, expression, dictionary):
|
||||
(quote, (x, stack)) = stack
|
||||
expression = x, expression
|
||||
return stack, pushback(quote, expression), dictionary
|
||||
<pre>@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.
|
||||
::
|
||||
|
||||
... x [Q] dip
|
||||
-------------------
|
||||
... Q x
|
||||
|
||||
'''
|
||||
(quote, (x, stack)) = stack
|
||||
expression = (x, expression)
|
||||
return stack, concat(quote, expression), dictionary
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -12539,28 +12569,26 @@ Any unbalanced square brackets will raise a ParseError.
|
|||
|
||||
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
<pre>second == rest first
|
||||
third == rest rest first
|
||||
<pre>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
|
||||
|
|
@ -12571,8 +12599,12 @@ 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
|
||||
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
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -11920,7 +11920,7 @@ key left-keys right-keys
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [6]:</div>
|
||||
<div class="prompt input_prompt">In [1]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="kn">from</span> <span class="nn">notebook_preamble</span> <span class="kn">import</span> <span class="n">D</span><span class="p">,</span> <span class="n">J</span><span class="p">,</span> <span class="n">V</span><span class="p">,</span> <span class="n">define</span><span class="p">,</span> <span class="n">DefinitionWrapper</span>
|
||||
|
|
@ -13008,11 +13008,11 @@ E == pop swap roll< rest rest cons cons
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [11]:</div>
|
||||
<div class="prompt input_prompt">In [30]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="kn">from</span> <span class="nn">joy.library</span> <span class="kn">import</span> <span class="n">FunctionWrapper</span>
|
||||
<span class="kn">from</span> <span class="nn">joy.utils.stack</span> <span class="kn">import</span> <span class="n">pushback</span>
|
||||
<span class="kn">from</span> <span class="nn">joy.utils.stack</span> <span class="kn">import</span> <span class="n">concat</span>
|
||||
<span class="kn">from</span> <span class="nn">notebook_preamble</span> <span class="kn">import</span> <span class="n">D</span>
|
||||
|
||||
|
||||
|
|
@ -13035,7 +13035,7 @@ E == pop swap roll< rest rest cons cons
|
|||
<span class="sd"> L</span>
|
||||
<span class="sd"> '''</span>
|
||||
<span class="n">L</span><span class="p">,</span> <span class="p">(</span><span class="n">E</span><span class="p">,</span> <span class="p">(</span><span class="n">G</span><span class="p">,</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">stack</span><span class="p">))))</span> <span class="o">=</span> <span class="n">stack</span>
|
||||
<span class="n">expression</span> <span class="o">=</span> <span class="n">pushback</span><span class="p">(</span><span class="n">G</span> <span class="k">if</span> <span class="n">a</span> <span class="o">></span> <span class="n">b</span> <span class="k">else</span> <span class="n">L</span> <span class="k">if</span> <span class="n">a</span> <span class="o"><</span> <span class="n">b</span> <span class="k">else</span> <span class="n">E</span><span class="p">,</span> <span class="n">expression</span><span class="p">)</span>
|
||||
<span class="n">expression</span> <span class="o">=</span> <span class="n">concat</span><span class="p">(</span><span class="n">G</span> <span class="k">if</span> <span class="n">a</span> <span class="o">></span> <span class="n">b</span> <span class="k">else</span> <span class="n">L</span> <span class="k">if</span> <span class="n">a</span> <span class="o"><</span> <span class="n">b</span> <span class="k">else</span> <span class="n">E</span><span class="p">,</span> <span class="n">expression</span><span class="p">)</span>
|
||||
<span class="k">return</span> <span class="n">stack</span><span class="p">,</span> <span class="n">expression</span><span class="p">,</span> <span class="n">dictionary</span>
|
||||
|
||||
|
||||
|
|
@ -13049,7 +13049,7 @@ E == pop swap roll< rest rest cons cons
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [14]:</div>
|
||||
<div class="prompt input_prompt">In [31]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="kn">from</span> <span class="nn">joy.library</span> <span class="kn">import</span> <span class="n">FunctionWrapper</span><span class="p">,</span> <span class="n">S_ifte</span>
|
||||
|
|
@ -13102,7 +13102,7 @@ E == pop swap roll< rest rest cons cons
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [31]:</div>
|
||||
<div class="prompt input_prompt">In [32]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s2">"1 0 ['G'] ['E'] ['L'] cmp"</span><span class="p">)</span>
|
||||
|
|
@ -13133,7 +13133,7 @@ E == pop swap roll< rest rest cons cons
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [32]:</div>
|
||||
<div class="prompt input_prompt">In [33]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s2">"1 1 ['G'] ['E'] ['L'] cmp"</span><span class="p">)</span>
|
||||
|
|
@ -13164,7 +13164,7 @@ E == pop swap roll< rest rest cons cons
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [33]:</div>
|
||||
<div class="prompt input_prompt">In [34]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s2">"0 1 ['G'] ['E'] ['L'] cmp"</span><span class="p">)</span>
|
||||
|
|
@ -13195,7 +13195,7 @@ E == pop swap roll< rest rest cons cons
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [34]:</div>
|
||||
<div class="prompt input_prompt">In [35]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="kn">from</span> <span class="nn">joy.library</span> <span class="kn">import</span> <span class="n">DefinitionWrapper</span>
|
||||
|
|
@ -13220,7 +13220,7 @@ E == pop swap roll< rest rest cons cons
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [35]:</div>
|
||||
<div class="prompt input_prompt">In [36]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s1">'[] 23 "b" BTree-add'</span><span class="p">)</span> <span class="c1"># Initial</span>
|
||||
|
|
@ -13251,7 +13251,7 @@ E == pop swap roll< rest rest cons cons
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [36]:</div>
|
||||
<div class="prompt input_prompt">In [37]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s1">'["b" 23 [] []] 88 "c" BTree-add'</span><span class="p">)</span> <span class="c1"># Less than</span>
|
||||
|
|
@ -13282,7 +13282,7 @@ E == pop swap roll< rest rest cons cons
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [37]:</div>
|
||||
<div class="prompt input_prompt">In [38]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s1">'["b" 23 [] []] 88 "a" BTree-add'</span><span class="p">)</span> <span class="c1"># Greater than</span>
|
||||
|
|
@ -13313,7 +13313,7 @@ E == pop swap roll< rest rest cons cons
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [38]:</div>
|
||||
<div class="prompt input_prompt">In [39]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s1">'["b" 23 [] []] 88 "b" BTree-add'</span><span class="p">)</span> <span class="c1"># Equal to</span>
|
||||
|
|
@ -13344,7 +13344,7 @@ E == pop swap roll< rest rest cons cons
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [39]:</div>
|
||||
<div class="prompt input_prompt">In [40]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s1">'[] 23 "a" BTree-add 88 "b" BTree-add 44 "c" BTree-add'</span><span class="p">)</span> <span class="c1"># Series.</span>
|
||||
|
|
@ -13503,7 +13503,7 @@ BTree-iter-order == [not] [pop] [dup third] [proc_left proc_current proc_right]
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [40]:</div>
|
||||
<div class="prompt input_prompt">In [41]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">define</span><span class="p">(</span><span class="s1">'BTree-iter-order == [not] [pop] [dup third] [[cons dip] dupdip [[first] dupdip] dip [rest rest rest first] dip i] genrec'</span><span class="p">)</span>
|
||||
|
|
@ -13516,7 +13516,7 @@ BTree-iter-order == [not] [pop] [dup third] [proc_left proc_current proc_right]
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [41]:</div>
|
||||
<div class="prompt input_prompt">In [42]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s1">'[3 9 5 2 8 6 7 8 4] to_set BTree-iter-order'</span><span class="p">)</span>
|
||||
|
|
@ -13667,7 +13667,7 @@ BTree-get == [pop not] swap [] [P [T>] [E] [T<] cmp] genrec</code></pre>
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [42]:</div>
|
||||
<div class="prompt input_prompt">In [43]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="c1"># I don't want to deal with name conflicts with the above so I'm inlining everything here.</span>
|
||||
|
|
@ -13694,7 +13694,7 @@ BTree-get == [pop not] swap [] [P [T>] [E] [T<] cmp] genrec</code></pre>
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [43]:</div>
|
||||
<div class="prompt input_prompt">In [44]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s1">'[] "gary" [popop "err"] BTree-get'</span><span class="p">)</span>
|
||||
|
|
@ -13725,7 +13725,7 @@ BTree-get == [pop not] swap [] [P [T>] [E] [T<] cmp] genrec</code></pre>
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [44]:</div>
|
||||
<div class="prompt input_prompt">In [45]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s1">'["gary" 23 [] []] "gary" [popop "err"] BTree-get'</span><span class="p">)</span>
|
||||
|
|
@ -13756,7 +13756,7 @@ BTree-get == [pop not] swap [] [P [T>] [E] [T<] cmp] genrec</code></pre>
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [45]:</div>
|
||||
<div class="prompt input_prompt">In [46]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s1">'''</span>
|
||||
|
|
@ -14271,7 +14271,7 @@ BTree-Delete == [pop not] swap [R0] [R1] genrec
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [20]:</div>
|
||||
<div class="prompt input_prompt">In [47]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">DefinitionWrapper</span><span class="o">.</span><span class="n">add_definitions</span><span class="p">(</span><span class="s1">'''</span>
|
||||
|
|
@ -14298,7 +14298,7 @@ BTree-Delete == [pop not] swap [R0] [R1] genrec
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [23]:</div>
|
||||
<div class="prompt input_prompt">In [48]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s2">"['a' 23 [] ['b' 88 [] ['c' 44 [] []]]] 'c' ['Er'] BTree-Delete "</span><span class="p">)</span>
|
||||
|
|
@ -14329,7 +14329,7 @@ BTree-Delete == [pop not] swap [R0] [R1] genrec
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [24]:</div>
|
||||
<div class="prompt input_prompt">In [49]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s2">"['a' 23 [] ['b' 88 [] ['c' 44 [] []]]] 'b' ['Er'] BTree-Delete "</span><span class="p">)</span>
|
||||
|
|
@ -14360,7 +14360,7 @@ BTree-Delete == [pop not] swap [R0] [R1] genrec
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [25]:</div>
|
||||
<div class="prompt input_prompt">In [50]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s2">"['a' 23 [] ['b' 88 [] ['c' 44 [] []]]] 'a' ['Er'] BTree-Delete "</span><span class="p">)</span>
|
||||
|
|
@ -14391,7 +14391,7 @@ BTree-Delete == [pop not] swap [R0] [R1] genrec
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [26]:</div>
|
||||
<div class="prompt input_prompt">In [51]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s2">"['a' 23 [] ['b' 88 [] ['c' 44 [] []]]] 'der' ['Er'] BTree-Delete "</span><span class="p">)</span>
|
||||
|
|
@ -14422,7 +14422,7 @@ BTree-Delete == [pop not] swap [R0] [R1] genrec
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [30]:</div>
|
||||
<div class="prompt input_prompt">In [52]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s2">"['a' 23 [] ['b' 88 [] ['c' 44 [] []]]] 'der' [pop] BTree-Delete "</span><span class="p">)</span>
|
||||
|
|
@ -14598,7 +14598,7 @@ treestep == swap [map] swoncat [TS1 [TS0] dip] dip genrec</code></pre>
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [46]:</div>
|
||||
<div class="prompt input_prompt">In [53]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">DefinitionWrapper</span><span class="o">.</span><span class="n">add_definitions</span><span class="p">(</span><span class="s1">'''</span>
|
||||
|
|
@ -14634,7 +14634,7 @@ treestep == swap [map] swoncat [TS1 [TS0] dip] dip genrec</code></pre>
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [47]:</div>
|
||||
<div class="prompt input_prompt">In [54]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s1">'[] 0 [sum +] [] treestep'</span><span class="p">)</span>
|
||||
|
|
@ -14665,7 +14665,7 @@ treestep == swap [map] swoncat [TS1 [TS0] dip] dip genrec</code></pre>
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [48]:</div>
|
||||
<div class="prompt input_prompt">In [55]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s1">'[23 []] 0 [sum +] [] treestep'</span><span class="p">)</span>
|
||||
|
|
@ -14696,7 +14696,7 @@ treestep == swap [map] swoncat [TS1 [TS0] dip] dip genrec</code></pre>
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [49]:</div>
|
||||
<div class="prompt input_prompt">In [56]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s1">'[23 [[2 []] [3 []]]] 0 [sum +] [] treestep'</span><span class="p">)</span>
|
||||
|
|
@ -14762,7 +14762,7 @@ K == [not] [pop z] [uncons [N] dip] [map C] genrec</code></pre>
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [50]:</div>
|
||||
<div class="prompt input_prompt">In [57]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">define</span><span class="p">(</span><span class="s1">'TS1 == [dip] cons [uncons] swoncat'</span><span class="p">)</span> <span class="c1"># We only need to redefine one word.</span>
|
||||
|
|
@ -14775,7 +14775,7 @@ K == [not] [pop z] [uncons [N] dip] [map C] genrec</code></pre>
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [51]:</div>
|
||||
<div class="prompt input_prompt">In [58]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s1">'[23 [2] [3]] 0 [sum +] [] treestep'</span><span class="p">)</span>
|
||||
|
|
@ -14806,7 +14806,7 @@ K == [not] [pop z] [uncons [N] dip] [map C] genrec</code></pre>
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [52]:</div>
|
||||
<div class="prompt input_prompt">In [59]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s1">'[23 [2 [8] [9]] [3] [4 []]] 0 [sum +] [] treestep'</span><span class="p">)</span>
|
||||
|
|
@ -14879,7 +14879,7 @@ key lkey rkey</code></pre>
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [53]:</div>
|
||||
<div class="prompt input_prompt">In [60]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s1">'[[3 0] [[2 0] [] []] [[9 0] [[5 0] [[4 0] [] []] [[8 0] [[6 0] [] [[7 0] [] []]] []]] []]] 23 [i] [uncons pop] treestep'</span><span class="p">)</span>
|
||||
|
|
@ -14932,7 +14932,7 @@ key [ lk rk ] cons
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [57]:</div>
|
||||
<div class="prompt input_prompt">In [61]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s1">'[[3 0] [[2 0] [] []] [[9 0] [[5 0] [[4 0] [] []] [[8 0] [[6 0] [] [[7 0] [] []]] []]] []]] [] [flatten cons] [first] treestep'</span><span class="p">)</span>
|
||||
|
|
@ -14985,7 +14985,7 @@ key [lk] [rk] roll<
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [55]:</div>
|
||||
<div class="prompt input_prompt">In [62]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython2"><pre><span></span><span class="n">J</span><span class="p">(</span><span class="s1">'[[3 0] [[2 0] [] []] [[9 0] [[5 0] [[4 0] [] []] [[8 0] [[6 0] [] [[7 0] [] []]] []]] []]] [] [i roll< swons concat] [uncons pop] treestep'</span><span class="p">)</span>
|
||||
|
|
|
|||
|
|
@ -584,7 +584,7 @@ The definition is a little longer but, I think, more elegant and easier to under
|
|||
|
||||
```python
|
||||
from joy.library import FunctionWrapper
|
||||
from joy.utils.stack import pushback
|
||||
from joy.utils.stack import concat
|
||||
from notebook_preamble import D
|
||||
|
||||
|
||||
|
|
@ -607,7 +607,7 @@ def cmp_(stack, expression, dictionary):
|
|||
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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -768,7 +768,7 @@ to understand:
|
|||
.. code:: ipython2
|
||||
|
||||
from joy.library import FunctionWrapper
|
||||
from joy.utils.stack import pushback
|
||||
from joy.utils.stack import concat
|
||||
from notebook_preamble import D
|
||||
|
||||
|
||||
|
|
@ -791,7 +791,7 @@ to understand:
|
|||
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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -245,42 +245,43 @@
|
|||
|
||||
|
||||
<span class="n">definitions</span> <span class="o">=</span> <span class="p">(</span><span class="s1">'''</span><span class="se">\</span>
|
||||
<span class="s1">ii == [dip] dupdip i</span>
|
||||
<span class="s1">of == swap at</span>
|
||||
<span class="s1">product == 1 swap [*] step</span>
|
||||
<span class="s1">flatten == [] swap [concat] step</span>
|
||||
<span class="s1">quoted == [unit] dip</span>
|
||||
<span class="s1">unquoted == [i] dip</span>
|
||||
<span class="s1">enstacken == stack [clear] dip</span>
|
||||
<span class="s1">? == dup truthy</span>
|
||||
<span class="s1">disenstacken == ? [uncons ?] loop pop</span>
|
||||
<span class="s1">dinfrirst == dip infra first</span>
|
||||
<span class="s1">nullary == [stack] dinfrirst</span>
|
||||
<span class="s1">unary == nullary popd</span>
|
||||
<span class="s1">binary == nullary [popop] dip</span>
|
||||
<span class="s1">ternary == unary [popop] dip</span>
|
||||
<span class="s1">pam == [i] map</span>
|
||||
<span class="s1">run == [] swap infra</span>
|
||||
<span class="s1">sqr == dup mul</span>
|
||||
<span class="s1">size == 0 swap [pop ++] step</span>
|
||||
<span class="s1">fork == [i] app2</span>
|
||||
<span class="s1">cleave == fork [popd] dip</span>
|
||||
<span class="s1">average == [sum 1.0 *] [size] cleave /</span>
|
||||
<span class="s1">gcd == 1 [tuck modulus dup 0 >] loop pop</span>
|
||||
<span class="s1">least_fraction == dup [gcd] infra [div] concat map</span>
|
||||
<span class="s1">*fraction == [uncons] dip uncons [swap] dip concat [*] infra [*] dip cons</span>
|
||||
<span class="s1">*fraction0 == concat [[swap] dip * [*] dip] infra</span>
|
||||
<span class="s1">down_to_zero == [0 >] [dup --] while</span>
|
||||
<span class="s1">range_to_zero == unit [down_to_zero] infra</span>
|
||||
<span class="s1">anamorphism == [pop []] swap [dip swons] genrec</span>
|
||||
<span class="s1">range == [0 <=] [1 - dup] anamorphism</span>
|
||||
<span class="s1">while == swap [nullary] cons dup dipd concat loop</span>
|
||||
<span class="s1">dupdipd == dup dipd</span>
|
||||
<span class="s1">primrec == [i] genrec</span>
|
||||
<span class="s1">step_zero == 0 roll> step</span>
|
||||
<span class="s1">average == [sum 1.0 *] [size] cleave /</span>
|
||||
<span class="s1">binary == nullary [popop] dip</span>
|
||||
<span class="s1">cleave == fork [popd] dip</span>
|
||||
<span class="s1">codireco == cons dip rest cons</span>
|
||||
<span class="s1">make_generator == [codireco] ccons</span>
|
||||
<span class="s1">dinfrirst == dip infra first</span>
|
||||
<span class="s1">disenstacken == ? [uncons ?] loop pop</span>
|
||||
<span class="s1">down_to_zero == [0 >] [dup --] while</span>
|
||||
<span class="s1">dupdipd == dup dipd</span>
|
||||
<span class="s1">enstacken == stack [clear] dip</span>
|
||||
<span class="s1">flatten == [] swap [concat] step</span>
|
||||
<span class="s1">fork == [i] app2</span>
|
||||
<span class="s1">gcd == 1 [tuck modulus dup 0 >] loop pop</span>
|
||||
<span class="s1">ifte == [nullary not] dipd branch</span>
|
||||
<span class="s1">ii == [dip] dupdip i</span>
|
||||
<span class="s1">least_fraction == dup [gcd] infra [div] concat map</span>
|
||||
<span class="s1">make_generator == [codireco] ccons</span>
|
||||
<span class="s1">nullary == [stack] dinfrirst</span>
|
||||
<span class="s1">of == swap at</span>
|
||||
<span class="s1">pam == [i] map</span>
|
||||
<span class="s1">primrec == [i] genrec</span>
|
||||
<span class="s1">product == 1 swap [*] step</span>
|
||||
<span class="s1">quoted == [unit] dip</span>
|
||||
<span class="s1">range == [0 <=] [1 - dup] anamorphism</span>
|
||||
<span class="s1">range_to_zero == unit [down_to_zero] infra</span>
|
||||
<span class="s1">run == [] swap infra</span>
|
||||
<span class="s1">size == 0 swap [pop ++] step</span>
|
||||
<span class="s1">sqr == dup mul</span>
|
||||
<span class="s1">step_zero == 0 roll> step</span>
|
||||
<span class="s1">swoncat == swap concat</span>
|
||||
<span class="s1">ternary == unary [popop] dip</span>
|
||||
<span class="s1">unary == nullary popd</span>
|
||||
<span class="s1">unquoted == [i] dip</span>
|
||||
<span class="s1">while == swap [nullary] cons dup dipd concat loop</span>
|
||||
<span class="s1">'''</span>
|
||||
<span class="c1">#</span>
|
||||
<span class="c1">#</span>
|
||||
|
|
@ -295,7 +296,6 @@
|
|||
<span class="c1">##second == rest first</span>
|
||||
<span class="c1">##third == rest rest first</span>
|
||||
<span class="c1">##swons == swap cons</span>
|
||||
<span class="c1">##swoncat == swap concat</span>
|
||||
|
||||
<span class="c1">##Zipper</span>
|
||||
<span class="c1">##z-down == [] swap uncons swap</span>
|
||||
|
|
|
|||
|
|
@ -499,7 +499,7 @@ machine transition table.</p>
|
|||
</div>
|
||||
<p>Says, “Three or more 1’s and not ending in 01 nor composed of all 1’s.”</p>
|
||||
<div class="figure" id="id2">
|
||||
<img alt="omg.svg" src="../_images/omg.svg" /><p class="caption"><span class="caption-text">omg.svg</span></p>
|
||||
<img alt="omg.svg" src="notebooks/attachment:omg.svg" /><p class="caption"><span class="caption-text">omg.svg</span></p>
|
||||
</div>
|
||||
<p>Start at <code class="docutils literal notranslate"><span class="pre">a</span></code> and follow the transition arrows according to their
|
||||
labels. Accepting states have a double outline. (Graphic generated with
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ provide control-flow and higher-order operations.</p>
|
|||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">dip</span><span class="p">(</span><span class="n">stack</span><span class="p">,</span> <span class="n">expression</span><span class="p">,</span> <span class="n">dictionary</span><span class="p">):</span>
|
||||
<span class="p">(</span><span class="n">quote</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">stack</span><span class="p">))</span> <span class="o">=</span> <span class="n">stack</span>
|
||||
<span class="n">expression</span> <span class="o">=</span> <span class="n">x</span><span class="p">,</span> <span class="n">expression</span>
|
||||
<span class="k">return</span> <span class="n">stack</span><span class="p">,</span> <span class="n">pushback</span><span class="p">(</span><span class="n">quote</span><span class="p">,</span> <span class="n">expression</span><span class="p">),</span> <span class="n">dictionary</span>
|
||||
<span class="k">return</span> <span class="n">stack</span><span class="p">,</span> <span class="n">concat</span><span class="p">(</span><span class="n">quote</span><span class="p">,</span> <span class="n">expression</span><span class="p">),</span> <span class="n">dictionary</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Some functions are defined in equations in terms of other functions.
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue