Bumped version to 0.2.0; docs edits.
I've added cond and cmp to the library so that should bump the minor version no. I think.
This commit is contained in:
+4
-38
@@ -1,21 +1,18 @@
|
||||
|
||||
Treating Trees II
|
||||
=================
|
||||
Treating Trees II: ``treestep``
|
||||
===============================
|
||||
|
||||
Let's consider a tree structure, similar to one described `"Why
|
||||
functional programming matters" by John
|
||||
Hughes <https://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pdf>`__,
|
||||
that consists of a node value followed by a sequence of zero or more
|
||||
child trees. (The asterisk is meant to indicate the `Kleene
|
||||
that consists of a node value followed by zero or more child trees. (The
|
||||
asterisk is meant to indicate the `Kleene
|
||||
star <https://en.wikipedia.org/wiki/Kleene_star>`__.)
|
||||
|
||||
::
|
||||
|
||||
tree = [] | [node tree*]
|
||||
|
||||
``treestep``
|
||||
------------
|
||||
|
||||
In the spirit of ``step`` we are going to define a combinator
|
||||
``treestep`` which expects a tree and three additional items: a
|
||||
base-case function ``[B]``, and two quoted programs ``[N]`` and ``[C]``.
|
||||
@@ -591,37 +588,6 @@ To me, that seems simpler than the ``genrec`` version.
|
||||
|
||||
''', D)
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
from joy.library import FunctionWrapper
|
||||
from joy.utils.stack import pushback
|
||||
|
||||
|
||||
@FunctionWrapper
|
||||
def cmp_(stack, expression, dictionary):
|
||||
'''
|
||||
cmp takes two values and three quoted programs on the stack and runs
|
||||
one of the three depending on the results of comparing the two values:
|
||||
|
||||
a b [G] [E] [L] cmp
|
||||
------------------------- a > b
|
||||
G
|
||||
|
||||
a b [G] [E] [L] cmp
|
||||
------------------------- a = b
|
||||
E
|
||||
|
||||
a b [G] [E] [L] cmp
|
||||
------------------------- a < b
|
||||
L
|
||||
'''
|
||||
L, (E, (G, (b, (a, stack)))) = stack
|
||||
expression = pushback(G if a > b else L if a < b else E, expression)
|
||||
return stack, expression, dictionary
|
||||
|
||||
|
||||
D['cmp'] = cmp_
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
J('''\
|
||||
|
||||
Reference in New Issue
Block a user