Simple type inference and compiler.
The compiler works for the subset of Joy functions that deal strictly in manipulating stacks and their contents.
This commit is contained in:
parent
ca05ea404a
commit
968556c7f3
1330
docs/Types.html
1330
docs/Types.html
File diff suppressed because it is too large
Load Diff
658
docs/Types.md
658
docs/Types.md
|
|
@ -1172,11 +1172,11 @@ def unify(u, v, s=None):
|
|||
if v >= u:
|
||||
s[v] = u
|
||||
return s
|
||||
raise ValueError('Cannot unify %r and %r.' % (u, v))
|
||||
raise TypeError('Cannot unify %r and %r.' % (u, v))
|
||||
|
||||
if isinstance(u, tuple) and isinstance(v, tuple):
|
||||
if len(u) != len(v) != 2:
|
||||
raise ValueError(repr((u, v)))
|
||||
raise TypeError(repr((u, v)))
|
||||
for uu, vv in zip(u, v):
|
||||
s = unify(uu, vv, s)
|
||||
if s == False: # (instead of a substitution dict.)
|
||||
|
|
@ -1185,13 +1185,13 @@ def unify(u, v, s=None):
|
|||
|
||||
if isinstance(v, tuple):
|
||||
if not stacky(u):
|
||||
raise ValueError('Cannot unify %r and %r.' % (u, v))
|
||||
raise TypeError('Cannot unify %r and %r.' % (u, v))
|
||||
s[u] = v
|
||||
return s
|
||||
|
||||
if isinstance(u, tuple):
|
||||
if not stacky(v):
|
||||
raise ValueError('Cannot unify %r and %r.' % (v, u))
|
||||
raise TypeError('Cannot unify %r and %r.' % (v, u))
|
||||
s[v] = u
|
||||
return s
|
||||
|
||||
|
|
@ -1796,9 +1796,90 @@ C(cons, unstack)
|
|||
|
||||
|
||||
|
||||
## Sets of Stack Effects
|
||||
## Multiple Stack Effects
|
||||
...
|
||||
|
||||
|
||||
```python
|
||||
class IntJoyType(NumberJoyType): prefix = 'i'
|
||||
|
||||
|
||||
F = map(FloatJoyType, _R)
|
||||
I = map(IntJoyType, _R)
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
muls = [
|
||||
((I[2], (I[1], S[0])), (I[3], S[0])),
|
||||
((F[2], (I[1], S[0])), (F[3], S[0])),
|
||||
((I[2], (F[1], S[0])), (F[3], S[0])),
|
||||
((F[2], (F[1], S[0])), (F[3], S[0])),
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
for f in muls:
|
||||
print doc_from_stack_effect(*f)
|
||||
```
|
||||
|
||||
(i1 i2 -- i3)
|
||||
(i1 f2 -- f3)
|
||||
(f1 i2 -- f3)
|
||||
(f1 f2 -- f3)
|
||||
|
||||
|
||||
|
||||
```python
|
||||
for f in muls:
|
||||
try:
|
||||
e = C(dup, f)
|
||||
except TypeError:
|
||||
continue
|
||||
print doc_from_stack_effect(*dup), doc_from_stack_effect(*f), doc_from_stack_effect(*e)
|
||||
```
|
||||
|
||||
(a1 -- a1 a1) (i1 i2 -- i3) (i0 -- i1)
|
||||
(a1 -- a1 a1) (f1 f2 -- f3) (f0 -- f1)
|
||||
|
||||
|
||||
|
||||
```python
|
||||
from itertools import product
|
||||
|
||||
|
||||
def meta_compose(F, G):
|
||||
for f, g in product(F, G):
|
||||
try:
|
||||
yield C(f, g)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
|
||||
def MC(F, G):
|
||||
return sorted(set(meta_compose(F, G)))
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
for f in MC([dup], muls):
|
||||
print doc_from_stack_effect(*f)
|
||||
```
|
||||
|
||||
(f0 -- f1)
|
||||
(i0 -- i1)
|
||||
|
||||
|
||||
|
||||
```python
|
||||
for f in MC([dup], [mul]):
|
||||
print doc_from_stack_effect(*f)
|
||||
```
|
||||
|
||||
(n0 -- n1)
|
||||
|
||||
|
||||
## `concat`
|
||||
|
||||
How to deal with `concat`?
|
||||
|
|
@ -1834,29 +1915,578 @@ As opposed to just:
|
|||
|
||||
(1 [.0.] [.1.] -- [.2.])
|
||||
|
||||
### Brzo...'s Derivitives of Regular Expressions
|
||||
|
||||
We can invent a new type of type variable, a "sequence type" (I think this is what they mean in the literature by that term...) or "Kleene Star" type. I'm going to represent it as a type letter and the asterix, so a sequence of zero or more `AnyJoyType` variables would be:
|
||||
|
||||
A*
|
||||
|
||||
The `A*` works by splitting the universe into two alternate histories:
|
||||
|
||||
A* -> 0 | A A*
|
||||
|
||||
The Kleene star variable disappears in one universe, and in the other it turns into an `AnyJoyType` variable followed by itself again. We have to return all universes (represented by their substitution dicts, the "unifiers") that don't lead to type conflicts.
|
||||
|
||||
Consider unifying two stacks (the lowercase letters are any type variables of the kinds we have defined so far):
|
||||
|
||||
[a A* b .0.] U [c d .1.]
|
||||
w/ {c: a}
|
||||
[ A* b .0.] U [ d .1.]
|
||||
|
||||
Now we have to split universes to unify `A*`. In the first universe it disappears:
|
||||
|
||||
[b .0.] U [d .1.]
|
||||
w/ {d: b, .1.: .0.}
|
||||
[] U []
|
||||
|
||||
While in the second it spawns an `A`, which we will label `e`:
|
||||
|
||||
[e A* b .0.] U [d .1.]
|
||||
w/ {d: e}
|
||||
[ A* b .0.] U [ .1.]
|
||||
w/ {.1.: A* b .0.}
|
||||
[ A* b .0.] U [ .1.]
|
||||
|
||||
Giving us two unifiers:
|
||||
|
||||
{c: a, d: b, .1.: .0.}
|
||||
{c: a, d: e, .1.: A* b .0.}
|
||||
|
||||
|
||||
```python
|
||||
class KleeneStar(object):
|
||||
|
||||
kind = AnyJoyType
|
||||
|
||||
def __init__(self, number):
|
||||
self.number = number
|
||||
self.count = 0
|
||||
self.prefix = repr(self)
|
||||
|
||||
def __repr__(self):
|
||||
return '%s%i*' % (self.kind.prefix, self.number)
|
||||
|
||||
def another(self):
|
||||
self.count += 1
|
||||
return self.kind(10000 * self.number + self.count)
|
||||
|
||||
def __eq__(self, other):
|
||||
return (
|
||||
isinstance(other, self.__class__)
|
||||
and other.number == self.number
|
||||
)
|
||||
|
||||
def __ge__(self, other):
|
||||
return self.kind >= other.kind
|
||||
|
||||
def __add__(self, other):
|
||||
return self.__class__(self.number + other)
|
||||
__radd__ = __add__
|
||||
|
||||
Which works but can lose information. Consider `cons concat`, this is how much information we *could* retain:
|
||||
def __hash__(self):
|
||||
return hash(repr(self))
|
||||
|
||||
(1 [.0.] [.1.] -- [1 .0. .1.]) uncons uncons
|
||||
class AnyStarJoyType(KleeneStar): kind = AnyJoyType
|
||||
class NumberStarJoyType(KleeneStar): kind = NumberJoyType
|
||||
#class FloatStarJoyType(KleeneStar): kind = FloatJoyType
|
||||
#class IntStarJoyType(KleeneStar): kind = IntJoyType
|
||||
class StackStarJoyType(KleeneStar): kind = StackJoyType
|
||||
|
||||
(1 [.0.] [.1.] -- 1 [.0. .1.]) uncons
|
||||
So far so good...
|
||||
(1 [2 .2.] [.1.] -- 1 2 [.2. .1.])
|
||||
|
||||
As = map(AnyStarJoyType, _R)
|
||||
Ns = map(NumberStarJoyType, _R)
|
||||
Ss = map(StackStarJoyType, _R)
|
||||
```
|
||||
|
||||
#### `unify()` version 4
|
||||
Can now return multiple results...
|
||||
|
||||
|
||||
```python
|
||||
def unify(u, v, s=None):
|
||||
if s is None:
|
||||
s = {}
|
||||
elif s:
|
||||
u = update(s, u)
|
||||
v = update(s, v)
|
||||
|
||||
if u == v:
|
||||
return s,
|
||||
|
||||
if isinstance(u, AnyJoyType) and isinstance(v, AnyJoyType):
|
||||
if u >= v:
|
||||
s[u] = v
|
||||
return s,
|
||||
if v >= u:
|
||||
s[v] = u
|
||||
return s,
|
||||
raise TypeError('Cannot unify %r and %r.' % (u, v))
|
||||
|
||||
if isinstance(u, tuple) and isinstance(v, tuple):
|
||||
if len(u) != len(v) != 2:
|
||||
raise TypeError(repr((u, v)))
|
||||
|
||||
a, b = v
|
||||
if isinstance(a, KleeneStar):
|
||||
# Two universes, in one the Kleene star disappears and unification
|
||||
# continues without it...
|
||||
s0 = unify(u, b)
|
||||
|
||||
# In the other it spawns a new variable.
|
||||
s1 = unify(u, (a.another(), v))
|
||||
|
||||
t = s0 + s1
|
||||
for sn in t:
|
||||
sn.update(s)
|
||||
return t
|
||||
|
||||
a, b = u
|
||||
if isinstance(a, KleeneStar):
|
||||
s0 = unify(v, b)
|
||||
s1 = unify(v, (a.another(), u))
|
||||
t = s0 + s1
|
||||
for sn in t:
|
||||
sn.update(s)
|
||||
return t
|
||||
|
||||
ses = unify(u[0], v[0])
|
||||
results = ()
|
||||
for sn in ses:
|
||||
results += unify(u[1], v[1], sn)
|
||||
return results
|
||||
|
||||
if isinstance(v, tuple):
|
||||
if not stacky(u):
|
||||
raise TypeError('Cannot unify %r and %r.' % (u, v))
|
||||
s[u] = v
|
||||
return s,
|
||||
|
||||
if isinstance(u, tuple):
|
||||
if not stacky(v):
|
||||
raise TypeError('Cannot unify %r and %r.' % (v, u))
|
||||
s[v] = u
|
||||
return s,
|
||||
|
||||
return ()
|
||||
|
||||
|
||||
def stacky(thing):
|
||||
return thing.__class__ in {AnyJoyType, StackJoyType}
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
a = (As[1], S[1])
|
||||
a
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
(1 [.0.] [.1.] -- 1 [.0. .1.]) ([a1 .10.] -- a1 [.10.])
|
||||
w/ { [a1 .10.] : [ .0. .1.] }
|
||||
-or-
|
||||
w/ { [ .0. .1.] : [a1 .10. ] }
|
||||
(a1*, s1)
|
||||
|
||||
|
||||
|
||||
|
||||
```python
|
||||
b = (A[1], S[2])
|
||||
b
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
(a1, s2)
|
||||
|
||||
|
||||
|
||||
|
||||
```python
|
||||
for result in unify(b, a):
|
||||
print result, '->', update(result, a), update(result, b)
|
||||
```
|
||||
|
||||
{s1: (a1, s2)} -> (a1*, (a1, s2)) (a1, s2)
|
||||
{a1: a10001, s2: (a1*, s1)} -> (a1*, s1) (a10001, (a1*, s1))
|
||||
|
||||
|
||||
|
||||
```python
|
||||
for result in unify(a, b):
|
||||
print result, '->', update(result, a), update(result, b)
|
||||
```
|
||||
|
||||
{s1: (a1, s2)} -> (a1*, (a1, s2)) (a1, s2)
|
||||
{a1: a10002, s2: (a1*, s1)} -> (a1*, s1) (a10002, (a1*, s1))
|
||||
|
||||
|
||||
|
||||
(a1*, s1) [a1*] (a1, s2) [a1]
|
||||
|
||||
(a1*, (a1, s2)) [a1* a1] (a1, s2) [a1]
|
||||
|
||||
(a1*, s1) [a1*] (a2, (a1*, s1)) [a2 a1*]
|
||||
|
||||
|
||||
```python
|
||||
sum_ = ((Ns[1], S[1]), S[0]), (N[0], S[0])
|
||||
|
||||
print doc_from_stack_effect(*sum_)
|
||||
```
|
||||
|
||||
([n1* .1.] -- n0)
|
||||
|
||||
|
||||
|
||||
```python
|
||||
f = (N[1], (N[2], (N[3], S[1]))), S[0]
|
||||
|
||||
print doc_from_stack_effect(S[0], f)
|
||||
```
|
||||
|
||||
(-- [n1 n2 n3 .1.])
|
||||
|
||||
|
||||
|
||||
```python
|
||||
for result in unify(sum_[0], f):
|
||||
print result, '->', update(result, sum_[1])
|
||||
```
|
||||
|
||||
{s1: (n1, (n2, (n3, s1)))} -> (n0, s0)
|
||||
{n1: n10001, s1: (n2, (n3, s1))} -> (n0, s0)
|
||||
{n1: n10001, s1: (n3, s1), n2: n10002} -> (n0, s0)
|
||||
{n1: n10001, s1: (n1*, s1), n3: n10003, n2: n10002} -> (n0, s0)
|
||||
|
||||
|
||||
#### `compose()` version 3
|
||||
This function has to be modified to use the new datastructures and it is no longer recursive, instead recursion happens as part of unification.
|
||||
|
||||
|
||||
```python
|
||||
def compose(f, g):
|
||||
|
||||
(f_in, f_out), (g_in, g_out) = f, g
|
||||
|
||||
if not g_in:
|
||||
yield f_in, stack_concat(g_out, f_out)
|
||||
|
||||
elif not f_out:
|
||||
yield stack_concat(f_in, g_in), g_out
|
||||
|
||||
else: # Unify and update.
|
||||
|
||||
s = unify(g_in, f_out)
|
||||
|
||||
if not s:
|
||||
raise TypeError('Cannot unify %r and %r.' % (fo, gi))
|
||||
|
||||
for result in s:
|
||||
yield update(result, (f_in, g_out))
|
||||
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
def meta_compose(F, G):
|
||||
for f, g in product(F, G):
|
||||
try:
|
||||
for result in C(f, g):
|
||||
yield result
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
|
||||
def C(f, g):
|
||||
f, g = relabel(f, g)
|
||||
for fg in compose(f, g):
|
||||
yield delabel(fg)
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
for f in MC([dup], muls):
|
||||
print doc_from_stack_effect(*f)
|
||||
```
|
||||
|
||||
(a0 -- f0)
|
||||
(a0 -- i0)
|
||||
|
||||
|
||||
|
||||
```python
|
||||
|
||||
|
||||
for f in MC([dup], [sum_]):
|
||||
print doc_from_stack_effect(*f)
|
||||
```
|
||||
|
||||
([n0* .0.] -- [n0* .0.] n0)
|
||||
|
||||
|
||||
|
||||
```python
|
||||
|
||||
|
||||
for f in MC([cons], [sum_]):
|
||||
print doc_from_stack_effect(*f)
|
||||
```
|
||||
|
||||
(a0 [.0.] -- n0)
|
||||
(n0 [n0* .0.] -- n1)
|
||||
|
||||
|
||||
|
||||
```python
|
||||
sum_ = (((N[1], (Ns[1], S[1])), S[0]), (N[0], S[0]))
|
||||
print doc_from_stack_effect(*cons),
|
||||
print doc_from_stack_effect(*sum_),
|
||||
|
||||
for f in MC([cons], [sum_]):
|
||||
print doc_from_stack_effect(*f)
|
||||
```
|
||||
|
||||
(a1 [.1.] -- [a1 .1.]) ([n1 n1* .1.] -- n0) (n0 [n0* .0.] -- n1)
|
||||
|
||||
|
||||
|
||||
```python
|
||||
a = (A[4], (As[1], (A[3], S[1])))
|
||||
a
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
(a4, (a1*, (a3, s1)))
|
||||
|
||||
|
||||
|
||||
|
||||
```python
|
||||
b = (A[1], (A[2], S[2]))
|
||||
b
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
(a1, (a2, s2))
|
||||
|
||||
|
||||
|
||||
|
||||
```python
|
||||
for result in unify(b, a):
|
||||
print result
|
||||
```
|
||||
|
||||
{a1: a4, s2: s1, a2: a3}
|
||||
{a1: a4, s2: (a1*, (a3, s1)), a2: a10003}
|
||||
|
||||
|
||||
|
||||
```python
|
||||
for result in unify(a, b):
|
||||
print result
|
||||
```
|
||||
|
||||
{s2: s1, a2: a3, a4: a1}
|
||||
{s2: (a1*, (a3, s1)), a2: a10004, a4: a1}
|
||||
|
||||
|
||||
### represent `concat`
|
||||
|
||||
([.0.] [.1.] -- [A*(.0.) .1.])
|
||||
|
||||
Meaning that `A*` on the right-hand side should all the crap from `.0.`.
|
||||
|
||||
([ .0.] [.1.] -- [ A* .1.])
|
||||
([a .0.] [.1.] -- [a A* .1.])
|
||||
([a b .0.] [.1.] -- [a b A* .1.])
|
||||
([a b c .0.] [.1.] -- [a b c A* .1.])
|
||||
|
||||
|
||||
|
||||
or...
|
||||
|
||||
([ .0.] [.1.] -- [ .1.])
|
||||
([a .0.] [.1.] -- [a .1.])
|
||||
([a b .0.] [.1.] -- [a b .1.])
|
||||
([a b c .0.] [.1.] -- [a b c .1.])
|
||||
([a A* c .0.] [.1.] -- [a A* c .1.])
|
||||
|
||||
|
||||
|
||||
(a, (b, S0)) . S1 = (a, (b, (A*, S1)))
|
||||
|
||||
|
||||
```python
|
||||
class Astar(object):
|
||||
def __repr__(self):
|
||||
return 'A*'
|
||||
|
||||
|
||||
def concat(s0, s1):
|
||||
a = []
|
||||
while isinstance(s0, tuple):
|
||||
term, s0 = s0
|
||||
a.append(term)
|
||||
assert isinstance(s0, StackJoyType), repr(s0)
|
||||
s1 = Astar(), s1
|
||||
for term in reversed(a):
|
||||
s1 = term, s1
|
||||
return s1
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
a, b = (A[1], S[0]), (A[2], S[1])
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
concat(a, b)
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
(a1, (A*, (a2, s1)))
|
||||
|
||||
|
||||
|
||||
## Joy in the Logical Paradigm
|
||||
For this to work the type label classes have to be modified to let `T >= t` succeed, where e.g. `T` is `IntJoyType` and `t` is `int`
|
||||
|
||||
|
||||
```python
|
||||
F = reduce(C, (pop, swap, roll_down, rest, rest, cons, cons))
|
||||
|
||||
print doc_from_stack_effect(*F)
|
||||
```
|
||||
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
ValueError Traceback (most recent call last)
|
||||
|
||||
<ipython-input-113-4b4cb6ff86e5> in <module>()
|
||||
1 F = reduce(C, (pop, swap, roll_down, rest, rest, cons, cons))
|
||||
2
|
||||
----> 3 print doc_from_stack_effect(*F)
|
||||
|
||||
|
||||
<ipython-input-101-ddee30dbb1a6> in C(f, g)
|
||||
10 def C(f, g):
|
||||
11 f, g = relabel(f, g)
|
||||
---> 12 for fg in compose(f, g):
|
||||
13 yield delabel(fg)
|
||||
|
||||
|
||||
<ipython-input-100-4237a6bb159d> in compose(f, g)
|
||||
1 def compose(f, g):
|
||||
2
|
||||
----> 3 (f_in, f_out), (g_in, g_out) = f, g
|
||||
4
|
||||
5 if not g_in:
|
||||
|
||||
|
||||
<ipython-input-101-ddee30dbb1a6> in C(f, g)
|
||||
10 def C(f, g):
|
||||
11 f, g = relabel(f, g)
|
||||
---> 12 for fg in compose(f, g):
|
||||
13 yield delabel(fg)
|
||||
|
||||
|
||||
<ipython-input-100-4237a6bb159d> in compose(f, g)
|
||||
1 def compose(f, g):
|
||||
2
|
||||
----> 3 (f_in, f_out), (g_in, g_out) = f, g
|
||||
4
|
||||
5 if not g_in:
|
||||
|
||||
|
||||
<ipython-input-101-ddee30dbb1a6> in C(f, g)
|
||||
10 def C(f, g):
|
||||
11 f, g = relabel(f, g)
|
||||
---> 12 for fg in compose(f, g):
|
||||
13 yield delabel(fg)
|
||||
|
||||
|
||||
<ipython-input-100-4237a6bb159d> in compose(f, g)
|
||||
1 def compose(f, g):
|
||||
2
|
||||
----> 3 (f_in, f_out), (g_in, g_out) = f, g
|
||||
4
|
||||
5 if not g_in:
|
||||
|
||||
|
||||
<ipython-input-101-ddee30dbb1a6> in C(f, g)
|
||||
10 def C(f, g):
|
||||
11 f, g = relabel(f, g)
|
||||
---> 12 for fg in compose(f, g):
|
||||
13 yield delabel(fg)
|
||||
|
||||
|
||||
<ipython-input-100-4237a6bb159d> in compose(f, g)
|
||||
1 def compose(f, g):
|
||||
2
|
||||
----> 3 (f_in, f_out), (g_in, g_out) = f, g
|
||||
4
|
||||
5 if not g_in:
|
||||
|
||||
|
||||
<ipython-input-101-ddee30dbb1a6> in C(f, g)
|
||||
10 def C(f, g):
|
||||
11 f, g = relabel(f, g)
|
||||
---> 12 for fg in compose(f, g):
|
||||
13 yield delabel(fg)
|
||||
|
||||
|
||||
<ipython-input-100-4237a6bb159d> in compose(f, g)
|
||||
1 def compose(f, g):
|
||||
2
|
||||
----> 3 (f_in, f_out), (g_in, g_out) = f, g
|
||||
4
|
||||
5 if not g_in:
|
||||
|
||||
|
||||
ValueError: need more than 1 value to unpack
|
||||
|
||||
|
||||
|
||||
```python
|
||||
from joy.parser import text_to_expression
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
s = text_to_expression('[3 4 ...] 2 1')
|
||||
s
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
L = unify(F[1], s)
|
||||
L
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
F[1]
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
F[1][0]
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
s[0]
|
||||
```
|
||||
|
||||
## Typing Combinators
|
||||
|
||||
TBD
|
||||
|
|
|
|||
725
docs/Types.rst
725
docs/Types.rst
|
|
@ -1410,11 +1410,11 @@ of how many labels of each domain it has "seen".
|
|||
if v >= u:
|
||||
s[v] = u
|
||||
return s
|
||||
raise ValueError('Cannot unify %r and %r.' % (u, v))
|
||||
raise TypeError('Cannot unify %r and %r.' % (u, v))
|
||||
|
||||
if isinstance(u, tuple) and isinstance(v, tuple):
|
||||
if len(u) != len(v) != 2:
|
||||
raise ValueError(repr((u, v)))
|
||||
raise TypeError(repr((u, v)))
|
||||
for uu, vv in zip(u, v):
|
||||
s = unify(uu, vv, s)
|
||||
if s == False: # (instead of a substitution dict.)
|
||||
|
|
@ -1423,13 +1423,13 @@ of how many labels of each domain it has "seen".
|
|||
|
||||
if isinstance(v, tuple):
|
||||
if not stacky(u):
|
||||
raise ValueError('Cannot unify %r and %r.' % (u, v))
|
||||
raise TypeError('Cannot unify %r and %r.' % (u, v))
|
||||
s[u] = v
|
||||
return s
|
||||
|
||||
if isinstance(u, tuple):
|
||||
if not stacky(v):
|
||||
raise ValueError('Cannot unify %r and %r.' % (v, u))
|
||||
raise TypeError('Cannot unify %r and %r.' % (v, u))
|
||||
s[v] = u
|
||||
return s
|
||||
|
||||
|
|
@ -2100,11 +2100,97 @@ comments are now already in the form needed for the Python code:
|
|||
|
||||
|
||||
|
||||
Sets of Stack Effects
|
||||
---------------------
|
||||
Multiple Stack Effects
|
||||
----------------------
|
||||
|
||||
...
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
class IntJoyType(NumberJoyType): prefix = 'i'
|
||||
|
||||
|
||||
F = map(FloatJoyType, _R)
|
||||
I = map(IntJoyType, _R)
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
muls = [
|
||||
((I[2], (I[1], S[0])), (I[3], S[0])),
|
||||
((F[2], (I[1], S[0])), (F[3], S[0])),
|
||||
((I[2], (F[1], S[0])), (F[3], S[0])),
|
||||
((F[2], (F[1], S[0])), (F[3], S[0])),
|
||||
]
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
for f in muls:
|
||||
print doc_from_stack_effect(*f)
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
(i1 i2 -- i3)
|
||||
(i1 f2 -- f3)
|
||||
(f1 i2 -- f3)
|
||||
(f1 f2 -- f3)
|
||||
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
for f in muls:
|
||||
try:
|
||||
e = C(dup, f)
|
||||
except TypeError:
|
||||
continue
|
||||
print doc_from_stack_effect(*dup), doc_from_stack_effect(*f), doc_from_stack_effect(*e)
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
(a1 -- a1 a1) (i1 i2 -- i3) (i0 -- i1)
|
||||
(a1 -- a1 a1) (f1 f2 -- f3) (f0 -- f1)
|
||||
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
from itertools import product
|
||||
|
||||
|
||||
def meta_compose(F, G):
|
||||
for f, g in product(F, G):
|
||||
try:
|
||||
yield C(f, g)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
|
||||
def MC(F, G):
|
||||
return sorted(set(meta_compose(F, G)))
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
for f in MC([dup], muls):
|
||||
print doc_from_stack_effect(*f)
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
(f0 -- f1)
|
||||
(i0 -- i1)
|
||||
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
for f in MC([dup], [mul]):
|
||||
print doc_from_stack_effect(*f)
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
(n0 -- n1)
|
||||
|
||||
|
||||
``concat``
|
||||
----------
|
||||
|
||||
|
|
@ -2150,24 +2236,631 @@ As opposed to just:
|
|||
|
||||
(1 [.0.] [.1.] -- [.2.])
|
||||
|
||||
Which works but can lose information. Consider ``cons concat``, this is
|
||||
how much information we *could* retain:
|
||||
Brzo...'s Derivitives of Regular Expressions
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
We can invent a new type of type variable, a "sequence type" (I think
|
||||
this is what they mean in the literature by that term...) or "Kleene
|
||||
Star" type. I'm going to represent it as a type letter and the asterix,
|
||||
so a sequence of zero or more ``AnyJoyType`` variables would be:
|
||||
|
||||
::
|
||||
|
||||
(1 [.0.] [.1.] -- [1 .0. .1.]) uncons uncons
|
||||
A*
|
||||
|
||||
(1 [.0.] [.1.] -- 1 [.0. .1.]) uncons
|
||||
So far so good...
|
||||
(1 [2 .2.] [.1.] -- 1 2 [.2. .1.])
|
||||
The ``A*`` works by splitting the universe into two alternate histories:
|
||||
|
||||
::
|
||||
|
||||
A* -> 0 | A A*
|
||||
|
||||
The Kleene star variable disappears in one universe, and in the other it
|
||||
turns into an ``AnyJoyType`` variable followed by itself again. We have
|
||||
to return all universes (represented by their substitution dicts, the
|
||||
"unifiers") that don't lead to type conflicts.
|
||||
|
||||
Consider unifying two stacks (the lowercase letters are any type
|
||||
variables of the kinds we have defined so far):
|
||||
|
||||
::
|
||||
|
||||
[a A* b .0.] U [c d .1.]
|
||||
w/ {c: a}
|
||||
[ A* b .0.] U [ d .1.]
|
||||
|
||||
Now we have to split universes to unify ``A*``. In the first universe it
|
||||
disappears:
|
||||
|
||||
::
|
||||
|
||||
[b .0.] U [d .1.]
|
||||
w/ {d: b, .1.: .0.}
|
||||
[] U []
|
||||
|
||||
While in the second it spawns an ``A``, which we will label ``e``:
|
||||
|
||||
::
|
||||
|
||||
[e A* b .0.] U [d .1.]
|
||||
w/ {d: e}
|
||||
[ A* b .0.] U [ .1.]
|
||||
w/ {.1.: A* b .0.}
|
||||
[ A* b .0.] U [ .1.]
|
||||
|
||||
Giving us two unifiers:
|
||||
|
||||
::
|
||||
|
||||
{c: a, d: b, .1.: .0.}
|
||||
{c: a, d: e, .1.: A* b .0.}
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
class KleeneStar(object):
|
||||
|
||||
kind = AnyJoyType
|
||||
|
||||
def __init__(self, number):
|
||||
self.number = number
|
||||
self.count = 0
|
||||
self.prefix = repr(self)
|
||||
|
||||
def __repr__(self):
|
||||
return '%s%i*' % (self.kind.prefix, self.number)
|
||||
|
||||
def another(self):
|
||||
self.count += 1
|
||||
return self.kind(10000 * self.number + self.count)
|
||||
|
||||
def __eq__(self, other):
|
||||
return (
|
||||
isinstance(other, self.__class__)
|
||||
and other.number == self.number
|
||||
)
|
||||
|
||||
def __ge__(self, other):
|
||||
return self.kind >= other.kind
|
||||
|
||||
def __add__(self, other):
|
||||
return self.__class__(self.number + other)
|
||||
__radd__ = __add__
|
||||
|
||||
def __hash__(self):
|
||||
return hash(repr(self))
|
||||
|
||||
class AnyStarJoyType(KleeneStar): kind = AnyJoyType
|
||||
class NumberStarJoyType(KleeneStar): kind = NumberJoyType
|
||||
#class FloatStarJoyType(KleeneStar): kind = FloatJoyType
|
||||
#class IntStarJoyType(KleeneStar): kind = IntJoyType
|
||||
class StackStarJoyType(KleeneStar): kind = StackJoyType
|
||||
|
||||
|
||||
As = map(AnyStarJoyType, _R)
|
||||
Ns = map(NumberStarJoyType, _R)
|
||||
Ss = map(StackStarJoyType, _R)
|
||||
|
||||
``unify()`` version 4
|
||||
^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Can now return multiple results...
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
def unify(u, v, s=None):
|
||||
if s is None:
|
||||
s = {}
|
||||
elif s:
|
||||
u = update(s, u)
|
||||
v = update(s, v)
|
||||
|
||||
if u == v:
|
||||
return s,
|
||||
|
||||
if isinstance(u, AnyJoyType) and isinstance(v, AnyJoyType):
|
||||
if u >= v:
|
||||
s[u] = v
|
||||
return s,
|
||||
if v >= u:
|
||||
s[v] = u
|
||||
return s,
|
||||
raise TypeError('Cannot unify %r and %r.' % (u, v))
|
||||
|
||||
if isinstance(u, tuple) and isinstance(v, tuple):
|
||||
if len(u) != len(v) != 2:
|
||||
raise TypeError(repr((u, v)))
|
||||
|
||||
a, b = v
|
||||
if isinstance(a, KleeneStar):
|
||||
# Two universes, in one the Kleene star disappears and unification
|
||||
# continues without it...
|
||||
s0 = unify(u, b)
|
||||
|
||||
# In the other it spawns a new variable.
|
||||
s1 = unify(u, (a.another(), v))
|
||||
|
||||
t = s0 + s1
|
||||
for sn in t:
|
||||
sn.update(s)
|
||||
return t
|
||||
|
||||
a, b = u
|
||||
if isinstance(a, KleeneStar):
|
||||
s0 = unify(v, b)
|
||||
s1 = unify(v, (a.another(), u))
|
||||
t = s0 + s1
|
||||
for sn in t:
|
||||
sn.update(s)
|
||||
return t
|
||||
|
||||
ses = unify(u[0], v[0])
|
||||
results = ()
|
||||
for sn in ses:
|
||||
results += unify(u[1], v[1], sn)
|
||||
return results
|
||||
|
||||
if isinstance(v, tuple):
|
||||
if not stacky(u):
|
||||
raise TypeError('Cannot unify %r and %r.' % (u, v))
|
||||
s[u] = v
|
||||
return s,
|
||||
|
||||
if isinstance(u, tuple):
|
||||
if not stacky(v):
|
||||
raise TypeError('Cannot unify %r and %r.' % (v, u))
|
||||
s[v] = u
|
||||
return s,
|
||||
|
||||
return ()
|
||||
|
||||
|
||||
def stacky(thing):
|
||||
return thing.__class__ in {AnyJoyType, StackJoyType}
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
a = (As[1], S[1])
|
||||
a
|
||||
|
||||
|
||||
|
||||
|
||||
(1 [.0.] [.1.] -- 1 [.0. .1.]) ([a1 .10.] -- a1 [.10.])
|
||||
w/ { [a1 .10.] : [ .0. .1.] }
|
||||
-or-
|
||||
w/ { [ .0. .1.] : [a1 .10. ] }
|
||||
.. parsed-literal::
|
||||
|
||||
(a1*, s1)
|
||||
|
||||
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
b = (A[1], S[2])
|
||||
b
|
||||
|
||||
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
(a1, s2)
|
||||
|
||||
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
for result in unify(b, a):
|
||||
print result, '->', update(result, a), update(result, b)
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
{s1: (a1, s2)} -> (a1*, (a1, s2)) (a1, s2)
|
||||
{a1: a10001, s2: (a1*, s1)} -> (a1*, s1) (a10001, (a1*, s1))
|
||||
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
for result in unify(a, b):
|
||||
print result, '->', update(result, a), update(result, b)
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
{s1: (a1, s2)} -> (a1*, (a1, s2)) (a1, s2)
|
||||
{a1: a10002, s2: (a1*, s1)} -> (a1*, s1) (a10002, (a1*, s1))
|
||||
|
||||
|
||||
::
|
||||
|
||||
(a1*, s1) [a1*] (a1, s2) [a1]
|
||||
|
||||
(a1*, (a1, s2)) [a1* a1] (a1, s2) [a1]
|
||||
|
||||
(a1*, s1) [a1*] (a2, (a1*, s1)) [a2 a1*]
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
sum_ = ((Ns[1], S[1]), S[0]), (N[0], S[0])
|
||||
|
||||
print doc_from_stack_effect(*sum_)
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
([n1* .1.] -- n0)
|
||||
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
f = (N[1], (N[2], (N[3], S[1]))), S[0]
|
||||
|
||||
print doc_from_stack_effect(S[0], f)
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
(-- [n1 n2 n3 .1.])
|
||||
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
for result in unify(sum_[0], f):
|
||||
print result, '->', update(result, sum_[1])
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
{s1: (n1, (n2, (n3, s1)))} -> (n0, s0)
|
||||
{n1: n10001, s1: (n2, (n3, s1))} -> (n0, s0)
|
||||
{n1: n10001, s1: (n3, s1), n2: n10002} -> (n0, s0)
|
||||
{n1: n10001, s1: (n1*, s1), n3: n10003, n2: n10002} -> (n0, s0)
|
||||
|
||||
|
||||
``compose()`` version 3
|
||||
^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
This function has to be modified to use the new datastructures and it is
|
||||
no longer recursive, instead recursion happens as part of unification.
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
def compose(f, g):
|
||||
|
||||
(f_in, f_out), (g_in, g_out) = f, g
|
||||
|
||||
if not g_in:
|
||||
yield f_in, stack_concat(g_out, f_out)
|
||||
|
||||
elif not f_out:
|
||||
yield stack_concat(f_in, g_in), g_out
|
||||
|
||||
else: # Unify and update.
|
||||
|
||||
s = unify(g_in, f_out)
|
||||
|
||||
if not s:
|
||||
raise TypeError('Cannot unify %r and %r.' % (fo, gi))
|
||||
|
||||
for result in s:
|
||||
yield update(result, (f_in, g_out))
|
||||
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
def meta_compose(F, G):
|
||||
for f, g in product(F, G):
|
||||
try:
|
||||
for result in C(f, g):
|
||||
yield result
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
|
||||
def C(f, g):
|
||||
f, g = relabel(f, g)
|
||||
for fg in compose(f, g):
|
||||
yield delabel(fg)
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
for f in MC([dup], muls):
|
||||
print doc_from_stack_effect(*f)
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
(a0 -- f0)
|
||||
(a0 -- i0)
|
||||
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
|
||||
|
||||
for f in MC([dup], [sum_]):
|
||||
print doc_from_stack_effect(*f)
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
([n0* .0.] -- [n0* .0.] n0)
|
||||
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
|
||||
|
||||
for f in MC([cons], [sum_]):
|
||||
print doc_from_stack_effect(*f)
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
(a0 [.0.] -- n0)
|
||||
(n0 [n0* .0.] -- n1)
|
||||
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
sum_ = (((N[1], (Ns[1], S[1])), S[0]), (N[0], S[0]))
|
||||
print doc_from_stack_effect(*cons),
|
||||
print doc_from_stack_effect(*sum_),
|
||||
|
||||
for f in MC([cons], [sum_]):
|
||||
print doc_from_stack_effect(*f)
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
(a1 [.1.] -- [a1 .1.]) ([n1 n1* .1.] -- n0) (n0 [n0* .0.] -- n1)
|
||||
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
a = (A[4], (As[1], (A[3], S[1])))
|
||||
a
|
||||
|
||||
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
(a4, (a1*, (a3, s1)))
|
||||
|
||||
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
b = (A[1], (A[2], S[2]))
|
||||
b
|
||||
|
||||
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
(a1, (a2, s2))
|
||||
|
||||
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
for result in unify(b, a):
|
||||
print result
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
{a1: a4, s2: s1, a2: a3}
|
||||
{a1: a4, s2: (a1*, (a3, s1)), a2: a10003}
|
||||
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
for result in unify(a, b):
|
||||
print result
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
{s2: s1, a2: a3, a4: a1}
|
||||
{s2: (a1*, (a3, s1)), a2: a10004, a4: a1}
|
||||
|
||||
|
||||
represent ``concat``
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
([.0.] [.1.] -- [A*(.0.) .1.])
|
||||
|
||||
Meaning that ``A*`` on the right-hand side should all the crap from
|
||||
``.0.``.
|
||||
|
||||
::
|
||||
|
||||
([ .0.] [.1.] -- [ A* .1.])
|
||||
([a .0.] [.1.] -- [a A* .1.])
|
||||
([a b .0.] [.1.] -- [a b A* .1.])
|
||||
([a b c .0.] [.1.] -- [a b c A* .1.])
|
||||
|
||||
or...
|
||||
|
||||
::
|
||||
|
||||
([ .0.] [.1.] -- [ .1.])
|
||||
([a .0.] [.1.] -- [a .1.])
|
||||
([a b .0.] [.1.] -- [a b .1.])
|
||||
([a b c .0.] [.1.] -- [a b c .1.])
|
||||
([a A* c .0.] [.1.] -- [a A* c .1.])
|
||||
|
||||
::
|
||||
|
||||
(a, (b, S0)) . S1 = (a, (b, (A*, S1)))
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
class Astar(object):
|
||||
def __repr__(self):
|
||||
return 'A*'
|
||||
|
||||
|
||||
def concat(s0, s1):
|
||||
a = []
|
||||
while isinstance(s0, tuple):
|
||||
term, s0 = s0
|
||||
a.append(term)
|
||||
assert isinstance(s0, StackJoyType), repr(s0)
|
||||
s1 = Astar(), s1
|
||||
for term in reversed(a):
|
||||
s1 = term, s1
|
||||
return s1
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
a, b = (A[1], S[0]), (A[2], S[1])
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
concat(a, b)
|
||||
|
||||
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
(a1, (A*, (a2, s1)))
|
||||
|
||||
|
||||
|
||||
Joy in the Logical Paradigm
|
||||
---------------------------
|
||||
|
||||
For this to work the type label classes have to be modified to let
|
||||
``T >= t`` succeed, where e.g. ``T`` is ``IntJoyType`` and ``t`` is
|
||||
``int``
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
F = reduce(C, (pop, swap, roll_down, rest, rest, cons, cons))
|
||||
|
||||
print doc_from_stack_effect(*F)
|
||||
|
||||
|
||||
::
|
||||
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
ValueError Traceback (most recent call last)
|
||||
|
||||
<ipython-input-113-4b4cb6ff86e5> in <module>()
|
||||
1 F = reduce(C, (pop, swap, roll_down, rest, rest, cons, cons))
|
||||
2
|
||||
----> 3 print doc_from_stack_effect(*F)
|
||||
|
||||
|
||||
<ipython-input-101-ddee30dbb1a6> in C(f, g)
|
||||
10 def C(f, g):
|
||||
11 f, g = relabel(f, g)
|
||||
---> 12 for fg in compose(f, g):
|
||||
13 yield delabel(fg)
|
||||
|
||||
|
||||
<ipython-input-100-4237a6bb159d> in compose(f, g)
|
||||
1 def compose(f, g):
|
||||
2
|
||||
----> 3 (f_in, f_out), (g_in, g_out) = f, g
|
||||
4
|
||||
5 if not g_in:
|
||||
|
||||
|
||||
<ipython-input-101-ddee30dbb1a6> in C(f, g)
|
||||
10 def C(f, g):
|
||||
11 f, g = relabel(f, g)
|
||||
---> 12 for fg in compose(f, g):
|
||||
13 yield delabel(fg)
|
||||
|
||||
|
||||
<ipython-input-100-4237a6bb159d> in compose(f, g)
|
||||
1 def compose(f, g):
|
||||
2
|
||||
----> 3 (f_in, f_out), (g_in, g_out) = f, g
|
||||
4
|
||||
5 if not g_in:
|
||||
|
||||
|
||||
<ipython-input-101-ddee30dbb1a6> in C(f, g)
|
||||
10 def C(f, g):
|
||||
11 f, g = relabel(f, g)
|
||||
---> 12 for fg in compose(f, g):
|
||||
13 yield delabel(fg)
|
||||
|
||||
|
||||
<ipython-input-100-4237a6bb159d> in compose(f, g)
|
||||
1 def compose(f, g):
|
||||
2
|
||||
----> 3 (f_in, f_out), (g_in, g_out) = f, g
|
||||
4
|
||||
5 if not g_in:
|
||||
|
||||
|
||||
<ipython-input-101-ddee30dbb1a6> in C(f, g)
|
||||
10 def C(f, g):
|
||||
11 f, g = relabel(f, g)
|
||||
---> 12 for fg in compose(f, g):
|
||||
13 yield delabel(fg)
|
||||
|
||||
|
||||
<ipython-input-100-4237a6bb159d> in compose(f, g)
|
||||
1 def compose(f, g):
|
||||
2
|
||||
----> 3 (f_in, f_out), (g_in, g_out) = f, g
|
||||
4
|
||||
5 if not g_in:
|
||||
|
||||
|
||||
<ipython-input-101-ddee30dbb1a6> in C(f, g)
|
||||
10 def C(f, g):
|
||||
11 f, g = relabel(f, g)
|
||||
---> 12 for fg in compose(f, g):
|
||||
13 yield delabel(fg)
|
||||
|
||||
|
||||
<ipython-input-100-4237a6bb159d> in compose(f, g)
|
||||
1 def compose(f, g):
|
||||
2
|
||||
----> 3 (f_in, f_out), (g_in, g_out) = f, g
|
||||
4
|
||||
5 if not g_in:
|
||||
|
||||
|
||||
ValueError: need more than 1 value to unpack
|
||||
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
from joy.parser import text_to_expression
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
s = text_to_expression('[3 4 ...] 2 1')
|
||||
s
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
L = unify(F[1], s)
|
||||
L
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
F[1]
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
F[1][0]
|
||||
|
||||
.. code:: ipython2
|
||||
|
||||
s[0]
|
||||
|
||||
Typing Combinators
|
||||
------------------
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
<ul><li><a href="joy/joy.html">joy.joy</a></li>
|
||||
<li><a href="joy/library.html">joy.library</a></li>
|
||||
<li><a href="joy/parser.html">joy.parser</a></li>
|
||||
<li><a href="joy/utils/generated_library.html">joy.utils.generated_library</a></li>
|
||||
<li><a href="joy/utils/pretty_print.html">joy.utils.pretty_print</a></li>
|
||||
<li><a href="joy/utils/stack.html">joy.utils.stack</a></li>
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -58,12 +58,15 @@
|
|||
<span class="sd">'''</span>
|
||||
<span class="kn">from</span> <span class="nn">inspect</span> <span class="k">import</span> <span class="n">getdoc</span>
|
||||
<span class="kn">from</span> <span class="nn">functools</span> <span class="k">import</span> <span class="n">wraps</span>
|
||||
<span class="kn">from</span> <span class="nn">inspect</span> <span class="k">import</span> <span class="n">getmembers</span><span class="p">,</span> <span class="n">isfunction</span>
|
||||
<span class="kn">import</span> <span class="nn">operator</span><span class="o">,</span> <span class="nn">math</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">.parser</span> <span class="k">import</span> <span class="n">text_to_expression</span><span class="p">,</span> <span class="n">Symbol</span>
|
||||
<span class="kn">from</span> <span class="nn">.utils.stack</span> <span class="k">import</span> <span class="n">list_to_stack</span><span class="p">,</span> <span class="n">iter_stack</span><span class="p">,</span> <span class="n">pick</span><span class="p">,</span> <span class="n">concat</span>
|
||||
<span class="kn">from</span> <span class="nn">.utils.brutal_hackery</span> <span class="k">import</span> <span class="n">rename_code_object</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">.utils</span> <span class="k">import</span> <span class="n">generated_library</span> <span class="k">as</span> <span class="n">genlib</span>
|
||||
|
||||
|
||||
<span class="n">_dictionary</span> <span class="o">=</span> <span class="p">{}</span>
|
||||
|
||||
|
|
@ -121,12 +124,8 @@
|
|||
|
||||
|
||||
<span class="n">definitions</span> <span class="o">=</span> <span class="p">(</span><span class="s1">'''</span><span class="se">\</span>
|
||||
<span class="s1">second == rest first</span>
|
||||
<span class="s1">third == rest rest first</span>
|
||||
<span class="s1">of == swap at</span>
|
||||
<span class="s1">product == 1 swap [*] step</span>
|
||||
<span class="s1">swons == swap cons</span>
|
||||
<span class="s1">swoncat == swap concat</span>
|
||||
<span class="s1">flatten == [] swap [concat] step</span>
|
||||
<span class="s1">unit == [] cons</span>
|
||||
<span class="s1">quoted == [unit] dip</span>
|
||||
|
|
@ -161,6 +160,10 @@
|
|||
<span class="s1">make_generator == [codireco] ccons</span>
|
||||
<span class="s1">ccons == cons cons</span>
|
||||
<span class="s1">'''</span>
|
||||
<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>
|
||||
|
|
@ -291,6 +294,11 @@
|
|||
<span class="c1">#</span>
|
||||
|
||||
|
||||
<span class="c1"># Load the auto-generated primitives into the dictionary.</span>
|
||||
<span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">primitive</span> <span class="ow">in</span> <span class="n">getmembers</span><span class="p">(</span><span class="n">genlib</span><span class="p">,</span> <span class="n">isfunction</span><span class="p">):</span>
|
||||
<span class="n">inscribe</span><span class="p">(</span><span class="n">SimpleFunctionWrapper</span><span class="p">(</span><span class="n">primitive</span><span class="p">))</span>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="parse"><a class="viewcode-back" href="../../library.html#joy.library.parse">[docs]</a><span class="nd">@inscribe</span>
|
||||
<span class="nd">@SimpleFunctionWrapper</span>
|
||||
<span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="n">stack</span><span class="p">):</span>
|
||||
|
|
@ -300,30 +308,30 @@
|
|||
<span class="k">return</span> <span class="n">expression</span><span class="p">,</span> <span class="n">stack</span></div>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="first"><a class="viewcode-back" href="../../library.html#joy.library.first">[docs]</a><span class="nd">@inscribe</span>
|
||||
<span class="nd">@SimpleFunctionWrapper</span>
|
||||
<span class="k">def</span> <span class="nf">first</span><span class="p">(</span><span class="n">stack</span><span class="p">):</span>
|
||||
<span class="sd">'''</span>
|
||||
<span class="sd"> ::</span>
|
||||
|
||||
<span class="sd"> first == uncons pop</span>
|
||||
|
||||
<span class="sd"> '''</span>
|
||||
<span class="p">((</span><span class="n">head</span><span class="p">,</span> <span class="n">tail</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="k">return</span> <span class="n">head</span><span class="p">,</span> <span class="n">stack</span></div>
|
||||
<span class="c1">##@inscribe</span>
|
||||
<span class="c1">##@SimpleFunctionWrapper</span>
|
||||
<span class="c1">##def first(stack):</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## ::</span>
|
||||
<span class="c1">##</span>
|
||||
<span class="c1">## first == uncons pop</span>
|
||||
<span class="c1">##</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## ((head, tail), stack) = stack</span>
|
||||
<span class="c1">## return head, stack</span>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="rest"><a class="viewcode-back" href="../../library.html#joy.library.rest">[docs]</a><span class="nd">@inscribe</span>
|
||||
<span class="nd">@SimpleFunctionWrapper</span>
|
||||
<span class="k">def</span> <span class="nf">rest</span><span class="p">(</span><span class="n">stack</span><span class="p">):</span>
|
||||
<span class="sd">'''</span>
|
||||
<span class="sd"> ::</span>
|
||||
|
||||
<span class="sd"> rest == uncons popd</span>
|
||||
|
||||
<span class="sd"> '''</span>
|
||||
<span class="p">((</span><span class="n">head</span><span class="p">,</span> <span class="n">tail</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="k">return</span> <span class="n">tail</span><span class="p">,</span> <span class="n">stack</span></div>
|
||||
<span class="c1">##@inscribe</span>
|
||||
<span class="c1">##@SimpleFunctionWrapper</span>
|
||||
<span class="c1">##def rest(stack):</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## ::</span>
|
||||
<span class="c1">##</span>
|
||||
<span class="c1">## rest == uncons popd</span>
|
||||
<span class="c1">##</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## ((head, tail), stack) = stack</span>
|
||||
<span class="c1">## return tail, stack</span>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="getitem"><a class="viewcode-back" href="../../library.html#joy.library.getitem">[docs]</a><span class="nd">@inscribe</span>
|
||||
|
|
@ -512,28 +520,28 @@
|
|||
<span class="k">return</span> <span class="n">list_to_stack</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">iter_stack</span><span class="p">(</span><span class="n">tos</span><span class="p">))),</span> <span class="n">stack</span></div>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="cons"><a class="viewcode-back" href="../../library.html#joy.library.cons">[docs]</a><span class="nd">@inscribe</span>
|
||||
<span class="nd">@SimpleFunctionWrapper</span>
|
||||
<span class="k">def</span> <span class="nf">cons</span><span class="p">(</span><span class="n">S</span><span class="p">):</span>
|
||||
<span class="sd">'''</span>
|
||||
<span class="sd"> The cons operator expects a list on top of the stack and the potential</span>
|
||||
<span class="sd"> member below. The effect is to add the potential member into the</span>
|
||||
<span class="sd"> aggregate.</span>
|
||||
<span class="sd"> '''</span>
|
||||
<span class="p">(</span><span class="n">tos</span><span class="p">,</span> <span class="p">(</span><span class="n">second</span><span class="p">,</span> <span class="n">stack</span><span class="p">))</span> <span class="o">=</span> <span class="n">S</span>
|
||||
<span class="k">return</span> <span class="p">(</span><span class="n">second</span><span class="p">,</span> <span class="n">tos</span><span class="p">),</span> <span class="n">stack</span></div>
|
||||
<span class="c1">##@inscribe</span>
|
||||
<span class="c1">##@SimpleFunctionWrapper</span>
|
||||
<span class="c1">##def cons(S):</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## The cons operator expects a list on top of the stack and the potential</span>
|
||||
<span class="c1">## member below. The effect is to add the potential member into the</span>
|
||||
<span class="c1">## aggregate.</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## (tos, (second, stack)) = S</span>
|
||||
<span class="c1">## return (second, tos), stack</span>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="uncons"><a class="viewcode-back" href="../../library.html#joy.library.uncons">[docs]</a><span class="nd">@inscribe</span>
|
||||
<span class="nd">@SimpleFunctionWrapper</span>
|
||||
<span class="k">def</span> <span class="nf">uncons</span><span class="p">(</span><span class="n">S</span><span class="p">):</span>
|
||||
<span class="sd">'''</span>
|
||||
<span class="sd"> Inverse of cons, removes an item from the top of the list on the stack</span>
|
||||
<span class="sd"> and places it under the remaining list.</span>
|
||||
<span class="sd"> '''</span>
|
||||
<span class="p">(</span><span class="n">tos</span><span class="p">,</span> <span class="n">stack</span><span class="p">)</span> <span class="o">=</span> <span class="n">S</span>
|
||||
<span class="n">item</span><span class="p">,</span> <span class="n">tos</span> <span class="o">=</span> <span class="n">tos</span>
|
||||
<span class="k">return</span> <span class="n">tos</span><span class="p">,</span> <span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">stack</span><span class="p">)</span></div>
|
||||
<span class="c1">##@inscribe</span>
|
||||
<span class="c1">##@SimpleFunctionWrapper</span>
|
||||
<span class="c1">##def uncons(S):</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## Inverse of cons, removes an item from the top of the list on the stack</span>
|
||||
<span class="c1">## and places it under the remaining list.</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## (tos, stack) = S</span>
|
||||
<span class="c1">## item, tos = tos</span>
|
||||
<span class="c1">## return tos, (item, stack)</span>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="clear"><a class="viewcode-back" href="../../library.html#joy.library.clear">[docs]</a><span class="nd">@inscribe</span>
|
||||
|
|
@ -549,52 +557,52 @@
|
|||
<span class="k">return</span> <span class="p">()</span></div>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="dup"><a class="viewcode-back" href="../../library.html#joy.library.dup">[docs]</a><span class="nd">@inscribe</span>
|
||||
<span class="nd">@SimpleFunctionWrapper</span>
|
||||
<span class="k">def</span> <span class="nf">dup</span><span class="p">(</span><span class="n">S</span><span class="p">):</span>
|
||||
<span class="sd">'''Duplicate the top item on the stack.'''</span>
|
||||
<span class="p">(</span><span class="n">tos</span><span class="p">,</span> <span class="n">stack</span><span class="p">)</span> <span class="o">=</span> <span class="n">S</span>
|
||||
<span class="k">return</span> <span class="n">tos</span><span class="p">,</span> <span class="p">(</span><span class="n">tos</span><span class="p">,</span> <span class="n">stack</span><span class="p">)</span></div>
|
||||
<span class="c1">##@inscribe</span>
|
||||
<span class="c1">##@SimpleFunctionWrapper</span>
|
||||
<span class="c1">##def dup(S):</span>
|
||||
<span class="c1">## '''Duplicate the top item on the stack.'''</span>
|
||||
<span class="c1">## (tos, stack) = S</span>
|
||||
<span class="c1">## return tos, (tos, stack)</span>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="over"><a class="viewcode-back" href="../../library.html#joy.library.over">[docs]</a><span class="nd">@inscribe</span>
|
||||
<span class="nd">@SimpleFunctionWrapper</span>
|
||||
<span class="k">def</span> <span class="nf">over</span><span class="p">(</span><span class="n">S</span><span class="p">):</span>
|
||||
<span class="sd">'''</span>
|
||||
<span class="sd"> Copy the second item down on the stack to the top of the stack.</span>
|
||||
<span class="sd"> ::</span>
|
||||
|
||||
<span class="sd"> a b over</span>
|
||||
<span class="sd"> --------------</span>
|
||||
<span class="sd"> a b a</span>
|
||||
|
||||
<span class="sd"> '''</span>
|
||||
<span class="n">second</span> <span class="o">=</span> <span class="n">S</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
|
||||
<span class="k">return</span> <span class="n">second</span><span class="p">,</span> <span class="n">S</span></div>
|
||||
<span class="c1">##@inscribe</span>
|
||||
<span class="c1">##@SimpleFunctionWrapper</span>
|
||||
<span class="c1">##def over(S):</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## Copy the second item down on the stack to the top of the stack.</span>
|
||||
<span class="c1">## ::</span>
|
||||
<span class="c1">##</span>
|
||||
<span class="c1">## a b over</span>
|
||||
<span class="c1">## --------------</span>
|
||||
<span class="c1">## a b a</span>
|
||||
<span class="c1">##</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## second = S[1][0]</span>
|
||||
<span class="c1">## return second, S</span>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="tuck"><a class="viewcode-back" href="../../library.html#joy.library.tuck">[docs]</a><span class="nd">@inscribe</span>
|
||||
<span class="nd">@SimpleFunctionWrapper</span>
|
||||
<span class="k">def</span> <span class="nf">tuck</span><span class="p">(</span><span class="n">S</span><span class="p">):</span>
|
||||
<span class="sd">'''</span>
|
||||
<span class="sd"> Copy the item at TOS under the second item of the stack.</span>
|
||||
<span class="sd"> ::</span>
|
||||
|
||||
<span class="sd"> a b tuck</span>
|
||||
<span class="sd"> --------------</span>
|
||||
<span class="sd"> b a b</span>
|
||||
|
||||
<span class="sd"> '''</span>
|
||||
<span class="p">(</span><span class="n">tos</span><span class="p">,</span> <span class="p">(</span><span class="n">second</span><span class="p">,</span> <span class="n">stack</span><span class="p">))</span> <span class="o">=</span> <span class="n">S</span>
|
||||
<span class="k">return</span> <span class="n">tos</span><span class="p">,</span> <span class="p">(</span><span class="n">second</span><span class="p">,</span> <span class="p">(</span><span class="n">tos</span><span class="p">,</span> <span class="n">stack</span><span class="p">))</span></div>
|
||||
<span class="c1">##@inscribe</span>
|
||||
<span class="c1">##@SimpleFunctionWrapper</span>
|
||||
<span class="c1">##def tuck(S):</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## Copy the item at TOS under the second item of the stack.</span>
|
||||
<span class="c1">## ::</span>
|
||||
<span class="c1">##</span>
|
||||
<span class="c1">## a b tuck</span>
|
||||
<span class="c1">## --------------</span>
|
||||
<span class="c1">## b a b</span>
|
||||
<span class="c1">##</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## (tos, (second, stack)) = S</span>
|
||||
<span class="c1">## return tos, (second, (tos, stack))</span>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="swap"><a class="viewcode-back" href="../../library.html#joy.library.swap">[docs]</a><span class="nd">@inscribe</span>
|
||||
<span class="nd">@SimpleFunctionWrapper</span>
|
||||
<span class="k">def</span> <span class="nf">swap</span><span class="p">(</span><span class="n">S</span><span class="p">):</span>
|
||||
<span class="sd">'''Swap the top two items on stack.'''</span>
|
||||
<span class="p">(</span><span class="n">tos</span><span class="p">,</span> <span class="p">(</span><span class="n">second</span><span class="p">,</span> <span class="n">stack</span><span class="p">))</span> <span class="o">=</span> <span class="n">S</span>
|
||||
<span class="k">return</span> <span class="n">second</span><span class="p">,</span> <span class="p">(</span><span class="n">tos</span><span class="p">,</span> <span class="n">stack</span><span class="p">)</span></div>
|
||||
<span class="c1">##@inscribe</span>
|
||||
<span class="c1">##@SimpleFunctionWrapper</span>
|
||||
<span class="c1">##def swap(S):</span>
|
||||
<span class="c1">## '''Swap the top two items on stack.'''</span>
|
||||
<span class="c1">## (tos, (second, stack)) = S</span>
|
||||
<span class="c1">## return second, (tos, stack)</span>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="swaack"><a class="viewcode-back" href="../../library.html#joy.library.swaack">[docs]</a><span class="nd">@inscribe</span>
|
||||
|
|
@ -605,14 +613,14 @@
|
|||
<span class="k">return</span> <span class="n">stack</span><span class="p">,</span> <span class="n">old_stack</span></div>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="stack_"><a class="viewcode-back" href="../../library.html#joy.library.stack_">[docs]</a><span class="nd">@inscribe</span>
|
||||
<span class="nd">@SimpleFunctionWrapper</span>
|
||||
<span class="k">def</span> <span class="nf">stack_</span><span class="p">(</span><span class="n">stack</span><span class="p">):</span>
|
||||
<span class="sd">'''</span>
|
||||
<span class="sd"> The stack operator pushes onto the stack a list containing all the</span>
|
||||
<span class="sd"> elements of the stack.</span>
|
||||
<span class="sd"> '''</span>
|
||||
<span class="k">return</span> <span class="n">stack</span><span class="p">,</span> <span class="n">stack</span></div>
|
||||
<span class="c1">##@inscribe</span>
|
||||
<span class="c1">##@SimpleFunctionWrapper</span>
|
||||
<span class="c1">##def stack_(stack):</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## The stack operator pushes onto the stack a list containing all the</span>
|
||||
<span class="c1">## elements of the stack.</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## return stack, stack</span>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="unstack"><a class="viewcode-back" href="../../library.html#joy.library.unstack">[docs]</a><span class="nd">@inscribe</span>
|
||||
|
|
@ -625,42 +633,42 @@
|
|||
<span class="k">return</span> <span class="n">stack</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></div>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="pop"><a class="viewcode-back" href="../../library.html#joy.library.pop">[docs]</a><span class="nd">@inscribe</span>
|
||||
<span class="nd">@SimpleFunctionWrapper</span>
|
||||
<span class="k">def</span> <span class="nf">pop</span><span class="p">(</span><span class="n">stack</span><span class="p">):</span>
|
||||
<span class="sd">'''Pop and discard the top item from the stack.'''</span>
|
||||
<span class="k">return</span> <span class="n">stack</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span></div>
|
||||
<span class="c1">##@inscribe</span>
|
||||
<span class="c1">##@SimpleFunctionWrapper</span>
|
||||
<span class="c1">##def pop(stack):</span>
|
||||
<span class="c1">## '''Pop and discard the top item from the stack.'''</span>
|
||||
<span class="c1">## return stack[1]</span>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="popd"><a class="viewcode-back" href="../../library.html#joy.library.popd">[docs]</a><span class="nd">@inscribe</span>
|
||||
<span class="nd">@SimpleFunctionWrapper</span>
|
||||
<span class="k">def</span> <span class="nf">popd</span><span class="p">(</span><span class="n">stack</span><span class="p">):</span>
|
||||
<span class="sd">'''Pop and discard the second item from the stack.'''</span>
|
||||
<span class="p">(</span><span class="n">tos</span><span class="p">,</span> <span class="p">(</span><span class="n">_</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="k">return</span> <span class="n">tos</span><span class="p">,</span> <span class="n">stack</span></div>
|
||||
<span class="c1">##@inscribe</span>
|
||||
<span class="c1">##@SimpleFunctionWrapper</span>
|
||||
<span class="c1">##def popd(stack):</span>
|
||||
<span class="c1">## '''Pop and discard the second item from the stack.'''</span>
|
||||
<span class="c1">## (tos, (_, stack)) = stack</span>
|
||||
<span class="c1">## return tos, stack</span>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="popdd"><a class="viewcode-back" href="../../library.html#joy.library.popdd">[docs]</a><span class="nd">@inscribe</span>
|
||||
<span class="nd">@SimpleFunctionWrapper</span>
|
||||
<span class="k">def</span> <span class="nf">popdd</span><span class="p">(</span><span class="n">stack</span><span class="p">):</span>
|
||||
<span class="sd">'''Pop and discard the third item from the stack.'''</span>
|
||||
<span class="p">(</span><span class="n">tos</span><span class="p">,</span> <span class="p">(</span><span class="n">second</span><span class="p">,</span> <span class="p">(</span><span class="n">_</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="k">return</span> <span class="n">tos</span><span class="p">,</span> <span class="p">(</span><span class="n">second</span><span class="p">,</span> <span class="n">stack</span><span class="p">)</span></div>
|
||||
<span class="c1">##@inscribe</span>
|
||||
<span class="c1">##@SimpleFunctionWrapper</span>
|
||||
<span class="c1">##def popdd(stack):</span>
|
||||
<span class="c1">## '''Pop and discard the third item from the stack.'''</span>
|
||||
<span class="c1">## (tos, (second, (_, stack))) = stack</span>
|
||||
<span class="c1">## return tos, (second, stack)</span>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="popop"><a class="viewcode-back" href="../../library.html#joy.library.popop">[docs]</a><span class="nd">@inscribe</span>
|
||||
<span class="nd">@SimpleFunctionWrapper</span>
|
||||
<span class="k">def</span> <span class="nf">popop</span><span class="p">(</span><span class="n">stack</span><span class="p">):</span>
|
||||
<span class="sd">'''Pop and discard the first and second items from the stack.'''</span>
|
||||
<span class="k">return</span> <span class="n">stack</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span></div>
|
||||
<span class="c1">##@inscribe</span>
|
||||
<span class="c1">##@SimpleFunctionWrapper</span>
|
||||
<span class="c1">##def popop(stack):</span>
|
||||
<span class="c1">## '''Pop and discard the first and second items from the stack.'''</span>
|
||||
<span class="c1">## return stack[1][1]</span>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="dupd"><a class="viewcode-back" href="../../library.html#joy.library.dupd">[docs]</a><span class="nd">@inscribe</span>
|
||||
<span class="nd">@SimpleFunctionWrapper</span>
|
||||
<span class="k">def</span> <span class="nf">dupd</span><span class="p">(</span><span class="n">S</span><span class="p">):</span>
|
||||
<span class="sd">'''Duplicate the second item on the stack.'''</span>
|
||||
<span class="p">(</span><span class="n">tos</span><span class="p">,</span> <span class="p">(</span><span class="n">second</span><span class="p">,</span> <span class="n">stack</span><span class="p">))</span> <span class="o">=</span> <span class="n">S</span>
|
||||
<span class="k">return</span> <span class="n">tos</span><span class="p">,</span> <span class="p">(</span><span class="n">second</span><span class="p">,</span> <span class="p">(</span><span class="n">second</span><span class="p">,</span> <span class="n">stack</span><span class="p">))</span></div>
|
||||
<span class="c1">##@inscribe</span>
|
||||
<span class="c1">##@SimpleFunctionWrapper</span>
|
||||
<span class="c1">##def dupd(S):</span>
|
||||
<span class="c1">## '''Duplicate the second item on the stack.'''</span>
|
||||
<span class="c1">## (tos, (second, stack)) = S</span>
|
||||
<span class="c1">## return tos, (second, (second, stack))</span>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="reverse"><a class="viewcode-back" href="../../library.html#joy.library.reverse">[docs]</a><span class="nd">@inscribe</span>
|
||||
|
|
@ -793,34 +801,34 @@
|
|||
<span class="k">return</span> <span class="n">r</span></div>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="rollup"><a class="viewcode-back" href="../../library.html#joy.library.rollup">[docs]</a><span class="nd">@inscribe</span>
|
||||
<span class="nd">@SimpleFunctionWrapper</span>
|
||||
<span class="k">def</span> <span class="nf">rollup</span><span class="p">(</span><span class="n">S</span><span class="p">):</span>
|
||||
<span class="sd">'''</span>
|
||||
<span class="sd"> ::</span>
|
||||
|
||||
<span class="sd"> a b c</span>
|
||||
<span class="sd"> -----------</span>
|
||||
<span class="sd"> b c a</span>
|
||||
|
||||
<span class="sd"> '''</span>
|
||||
<span class="p">(</span><span class="n">a</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">c</span><span class="p">,</span> <span class="n">stack</span><span class="p">)))</span> <span class="o">=</span> <span class="n">S</span>
|
||||
<span class="k">return</span> <span class="n">b</span><span class="p">,</span> <span class="p">(</span><span class="n">c</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></div>
|
||||
<span class="c1">##@inscribe</span>
|
||||
<span class="c1">##@SimpleFunctionWrapper</span>
|
||||
<span class="c1">##def rollup(S):</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## ::</span>
|
||||
<span class="c1">##</span>
|
||||
<span class="c1">## a b c</span>
|
||||
<span class="c1">## -----------</span>
|
||||
<span class="c1">## b c a</span>
|
||||
<span class="c1">##</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## (a, (b, (c, stack))) = S</span>
|
||||
<span class="c1">## return b, (c, (a, stack))</span>
|
||||
|
||||
|
||||
<div class="viewcode-block" id="rolldown"><a class="viewcode-back" href="../../library.html#joy.library.rolldown">[docs]</a><span class="nd">@inscribe</span>
|
||||
<span class="nd">@SimpleFunctionWrapper</span>
|
||||
<span class="k">def</span> <span class="nf">rolldown</span><span class="p">(</span><span class="n">S</span><span class="p">):</span>
|
||||
<span class="sd">'''</span>
|
||||
<span class="sd"> ::</span>
|
||||
|
||||
<span class="sd"> a b c</span>
|
||||
<span class="sd"> -----------</span>
|
||||
<span class="sd"> c a b</span>
|
||||
|
||||
<span class="sd"> '''</span>
|
||||
<span class="p">(</span><span class="n">a</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">c</span><span class="p">,</span> <span class="n">stack</span><span class="p">)))</span> <span class="o">=</span> <span class="n">S</span>
|
||||
<span class="k">return</span> <span class="n">c</span><span class="p">,</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">stack</span><span class="p">))</span></div>
|
||||
<span class="c1">##@inscribe</span>
|
||||
<span class="c1">##@SimpleFunctionWrapper</span>
|
||||
<span class="c1">##def rolldown(S):</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## ::</span>
|
||||
<span class="c1">##</span>
|
||||
<span class="c1">## a b c</span>
|
||||
<span class="c1">## -----------</span>
|
||||
<span class="c1">## c a b</span>
|
||||
<span class="c1">##</span>
|
||||
<span class="c1">## '''</span>
|
||||
<span class="c1">## (a, (b, (c, stack))) = S</span>
|
||||
<span class="c1">## return c, (a, (b, stack))</span>
|
||||
|
||||
|
||||
<span class="c1">#def execute(S):</span>
|
||||
|
|
|
|||
|
|
@ -11,3 +11,9 @@ Function Reference
|
|||
:members:
|
||||
|
||||
|
||||
Auto-generated Functions
|
||||
---------------------------
|
||||
|
||||
.. automodule:: joy.utils.generated_library
|
||||
:members:
|
||||
|
||||
|
|
|
|||
|
|
@ -96,6 +96,8 @@
|
|||
<h2 id="C">C</h2>
|
||||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="library.html#joy.utils.generated_library.ccons">ccons() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.choice">choice() (in module joy.library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.clear">clear() (in module joy.library)</a>
|
||||
|
|
@ -110,7 +112,7 @@
|
|||
</li>
|
||||
<li><a href="library.html#joy.library.cond">cond() (in module joy.library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.cons">cons() (in module joy.library)</a>
|
||||
<li><a href="library.html#joy.utils.generated_library.cons">cons() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
|
@ -126,15 +128,17 @@
|
|||
</li>
|
||||
<li><a href="library.html#joy.library.dipdd">dipdd() (in module joy.library)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="library.html#joy.library.divmod_">divmod_() (in module joy.library)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="library.html#joy.library.drop">drop() (in module joy.library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.dup">dup() (in module joy.library)</a>
|
||||
<li><a href="library.html#joy.utils.generated_library.dup">dup() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.dupd">dupd() (in module joy.library)</a>
|
||||
<li><a href="library.html#joy.utils.generated_library.dupd">dupd() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.utils.generated_library.dupdd">dupdd() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.dupdip">dupdip() (in module joy.library)</a>
|
||||
</li>
|
||||
|
|
@ -152,11 +156,15 @@
|
|||
<h2 id="F">F</h2>
|
||||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="library.html#joy.library.first">first() (in module joy.library)</a>
|
||||
<li><a href="library.html#joy.utils.generated_library.first">first() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.utils.generated_library.first_two">first_two() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="library.html#joy.library.floor">floor() (in module joy.library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.utils.generated_library.fourth">fourth() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.FunctionWrapper">FunctionWrapper() (in module joy.library)</a>
|
||||
</li>
|
||||
|
|
@ -219,6 +227,8 @@
|
|||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="parser.html#module-joy.parser">joy.parser (module)</a>
|
||||
</li>
|
||||
<li><a href="library.html#module-joy.utils.generated_library">joy.utils.generated_library (module)</a>
|
||||
</li>
|
||||
<li><a href="pretty.html#module-joy.utils.pretty_print">joy.utils.pretty_print (module)</a>
|
||||
</li>
|
||||
|
|
@ -256,7 +266,7 @@
|
|||
<h2 id="O">O</h2>
|
||||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="library.html#joy.library.over">over() (in module joy.library)</a>
|
||||
<li><a href="library.html#joy.utils.generated_library.over">over() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
|
@ -273,16 +283,20 @@
|
|||
<li><a href="stack.html#joy.utils.stack.pick">pick() (in module joy.utils.stack)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.pm">pm() (in module joy.library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.utils.generated_library.pop">pop() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="library.html#joy.library.pop">pop() (in module joy.library)</a>
|
||||
<li><a href="library.html#joy.utils.generated_library.popd">popd() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.popd">popd() (in module joy.library)</a>
|
||||
<li><a href="library.html#joy.utils.generated_library.popdd">popdd() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.popdd">popdd() (in module joy.library)</a>
|
||||
<li><a href="library.html#joy.utils.generated_library.popop">popop() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.popop">popop() (in module joy.library)</a>
|
||||
<li><a href="library.html#joy.utils.generated_library.popopd">popopd() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.utils.generated_library.popopdd">popopdd() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.pred">pred() (in module joy.library)</a>
|
||||
</li>
|
||||
|
|
@ -296,15 +310,17 @@
|
|||
</li>
|
||||
<li><a href="joy.html#joy.joy.repl">repl() (in module joy.joy)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.rest">rest() (in module joy.library)</a>
|
||||
<li><a href="library.html#joy.utils.generated_library.rest">rest() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.reverse">reverse() (in module joy.library)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="library.html#joy.library.reverse">reverse() (in module joy.library)</a>
|
||||
<li><a href="library.html#joy.utils.generated_library.rolldown">rolldown() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.rolldown">rolldown() (in module joy.library)</a>
|
||||
<li><a href="library.html#joy.utils.generated_library.rollup">rollup() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.rollup">rollup() (in module joy.library)</a>
|
||||
<li><a href="library.html#joy.utils.generated_library.rrest">rrest() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="joy.html#joy.joy.run">run() (in module joy.joy)</a>
|
||||
</li>
|
||||
|
|
@ -314,6 +330,8 @@
|
|||
<h2 id="S">S</h2>
|
||||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="library.html#joy.utils.generated_library.second">second() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.select">select() (in module joy.library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.sharing">sharing() (in module joy.library)</a>
|
||||
|
|
@ -326,13 +344,17 @@
|
|||
</li>
|
||||
<li><a href="library.html#joy.library.sqrt">sqrt() (in module joy.library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.stack_">stack_() (in module joy.library)</a>
|
||||
<li><a href="library.html#joy.utils.generated_library.stack">stack() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="stack.html#joy.utils.stack.stack_to_string">stack_to_string() (in module joy.utils.stack)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="stack.html#joy.utils.stack.stack_to_string">stack_to_string() (in module joy.utils.stack)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.step">step() (in module joy.library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.utils.generated_library.stuncons">stuncons() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.utils.generated_library.stununcons">stununcons() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.succ">succ() (in module joy.library)</a>
|
||||
</li>
|
||||
|
|
@ -340,7 +362,9 @@
|
|||
</li>
|
||||
<li><a href="library.html#joy.library.swaack">swaack() (in module joy.library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.swap">swap() (in module joy.library)</a>
|
||||
<li><a href="library.html#joy.utils.generated_library.swap">swap() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.utils.generated_library.swons">swons() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
<li><a href="parser.html#joy.parser.Symbol">Symbol (class in joy.parser)</a>
|
||||
</li>
|
||||
|
|
@ -353,6 +377,8 @@
|
|||
<li><a href="library.html#joy.library.take">take() (in module joy.library)</a>
|
||||
</li>
|
||||
<li><a href="parser.html#joy.parser.text_to_expression">text_to_expression() (in module joy.parser)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.utils.generated_library.third">third() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
|
|
@ -360,7 +386,7 @@
|
|||
</li>
|
||||
<li><a href="pretty.html#joy.utils.pretty_print.TracePrinter">TracePrinter (class in joy.utils.pretty_print)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.tuck">tuck() (in module joy.library)</a>
|
||||
<li><a href="library.html#joy.utils.generated_library.tuck">tuck() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
|
@ -370,13 +396,15 @@
|
|||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="library.html#joy.library.UnaryBuiltinWrapper">UnaryBuiltinWrapper() (in module joy.library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.uncons">uncons() (in module joy.library)</a>
|
||||
<li><a href="library.html#joy.utils.generated_library.uncons">uncons() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="library.html#joy.library.unique">unique() (in module joy.library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.library.unstack">unstack() (in module joy.library)</a>
|
||||
</li>
|
||||
<li><a href="library.html#joy.utils.generated_library.unswons">unswons() (in module joy.utils.generated_library)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ interesting aspects. It’s quite a treasure trove.</p>
|
|||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="library.html">Function Reference</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="library.html#module-joy.library"><code class="docutils literal notranslate"><span class="pre">joy.library</span></code></a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="library.html#module-joy.utils.generated_library">Auto-generated Functions</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="lib.html">Functions Grouped by, er, Function with Examples</a><ul>
|
||||
|
|
|
|||
|
|
@ -240,14 +240,6 @@ true. If no predicates return true the default function runs.</p>
|
|||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.cons">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">cons</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#cons"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.cons" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The cons operator expects a list on top of the stack and the potential
|
||||
member below. The effect is to add the potential member into the
|
||||
aggregate.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.dip">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">dip</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#dip"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.dip" title="Permalink to this definition">¶</a></dt>
|
||||
|
|
@ -305,18 +297,6 @@ n items removed off the top.</p>
|
|||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.dup">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">dup</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#dup"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.dup" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Duplicate the top item on the stack.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.dupd">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">dupd</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#dupd"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.dupd" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Duplicate the second item on the stack.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.dupdip">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">dupdip</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#dupdip"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.dupdip" title="Permalink to this definition">¶</a></dt>
|
||||
|
|
@ -330,14 +310,6 @@ n items removed off the top.</p>
|
|||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.first">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">first</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#first"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.first" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">first</span> <span class="o">==</span> <span class="n">uncons</span> <span class="n">pop</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.floor">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">floor</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#floor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.floor" title="Permalink to this definition">¶</a></dt>
|
||||
|
|
@ -509,17 +481,6 @@ new list with the results (in place of the program and original list.</p>
|
|||
<dd><p>Given a list find the minimum.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.over">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">over</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#over"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.over" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Copy the second item down on the stack to the top of the stack.</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span> <span class="n">a</span> <span class="n">b</span> <span class="n">over</span>
|
||||
<span class="o">--------------</span>
|
||||
<span class="n">a</span> <span class="n">b</span> <span class="n">a</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.parse">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">parse</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#parse"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.parse" title="Permalink to this definition">¶</a></dt>
|
||||
|
|
@ -537,30 +498,6 @@ new list with the results (in place of the program and original list.</p>
|
|||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.pop">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">pop</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#pop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.pop" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Pop and discard the top item from the stack.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.popd">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">popd</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#popd"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.popd" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Pop and discard the second item from the stack.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.popdd">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">popdd</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#popdd"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.popdd" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Pop and discard the third item from the stack.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.popop">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">popop</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#popop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.popop" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Pop and discard the first and second items from the stack.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.pred">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">pred</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#pred"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.pred" title="Permalink to this definition">¶</a></dt>
|
||||
|
|
@ -579,14 +516,6 @@ from the the quote. The item is only removed once.</p>
|
|||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.rest">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">rest</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#rest"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.rest" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">rest</span> <span class="o">==</span> <span class="n">uncons</span> <span class="n">popd</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.reverse">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">reverse</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#reverse"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.reverse" title="Permalink to this definition">¶</a></dt>
|
||||
|
|
@ -596,26 +525,6 @@ from the the quote. The item is only removed once.</p>
|
|||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.rolldown">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">rolldown</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#rolldown"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.rolldown" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span> <span class="n">a</span> <span class="n">b</span> <span class="n">c</span>
|
||||
<span class="o">-----------</span>
|
||||
<span class="n">c</span> <span class="n">a</span> <span class="n">b</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.rollup">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">rollup</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#rollup"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.rollup" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span> <span class="n">a</span> <span class="n">b</span> <span class="n">c</span>
|
||||
<span class="o">-----------</span>
|
||||
<span class="n">b</span> <span class="n">c</span> <span class="n">a</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.select">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">select</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#select"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.select" title="Permalink to this definition">¶</a></dt>
|
||||
|
|
@ -667,13 +576,6 @@ Boolean value (so empty string, zero, etc. are counted as false, etc.)</p>
|
|||
Negative numbers return complex roots.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.stack_">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">stack_</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#stack_"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.stack_" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The stack operator pushes onto the stack a list containing all the
|
||||
elements of the stack.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.step">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">step</code><span class="sig-paren">(</span><em>S</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#step"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.step" title="Permalink to this definition">¶</a></dt>
|
||||
|
|
@ -716,12 +618,6 @@ on top of the stack.</p>
|
|||
<dd><p>swap stack</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.swap">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">swap</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#swap"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.swap" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Swap the top two items on stack.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.take">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">take</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#take"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.take" title="Permalink to this definition">¶</a></dt>
|
||||
|
|
@ -756,24 +652,6 @@ use reverse if needed.)</p>
|
|||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.tuck">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">tuck</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#tuck"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.tuck" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Copy the item at TOS under the second item of the stack.</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span> <span class="n">a</span> <span class="n">b</span> <span class="n">tuck</span>
|
||||
<span class="o">--------------</span>
|
||||
<span class="n">b</span> <span class="n">a</span> <span class="n">b</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.uncons">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">uncons</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#uncons"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.uncons" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Inverse of cons, removes an item from the top of the list on the stack
|
||||
and places it under the remaining list.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.library.unique">
|
||||
<code class="descclassname">joy.library.</code><code class="descname">unique</code><span class="sig-paren">(</span><em>stack</em>, <em>expression</em>, <em>dictionary</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/library.html#unique"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.library.unique" title="Permalink to this definition">¶</a></dt>
|
||||
|
|
@ -824,6 +702,241 @@ the stack discarding the rest of the stack.</p>
|
|||
from each list. The smallest list sets the length of the result list.</p>
|
||||
</dd></dl>
|
||||
|
||||
</div>
|
||||
<div class="section" id="module-joy.utils.generated_library">
|
||||
<span id="auto-generated-functions"></span><h2>Auto-generated Functions<a class="headerlink" href="#module-joy.utils.generated_library" title="Permalink to this headline">¶</a></h2>
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.ccons">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">ccons</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#ccons"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.ccons" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a1</span> <span class="n">a0</span> <span class="p">[</span><span class="o">...</span><span class="mi">0</span><span class="p">]</span> <span class="o">--</span> <span class="p">[</span><span class="n">a1</span> <span class="n">a0</span> <span class="o">...</span><span class="mi">0</span><span class="p">])</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.cons">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">cons</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#cons"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.cons" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a1</span> <span class="p">[</span><span class="o">...</span><span class="mi">0</span><span class="p">]</span> <span class="o">--</span> <span class="p">[</span><span class="n">a1</span> <span class="o">...</span><span class="mi">0</span><span class="p">])</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.dup">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">dup</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#dup"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.dup" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a1</span> <span class="o">--</span> <span class="n">a1</span> <span class="n">a1</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.dupd">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">dupd</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#dupd"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.dupd" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a2</span> <span class="n">a1</span> <span class="o">--</span> <span class="n">a2</span> <span class="n">a2</span> <span class="n">a1</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.dupdd">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">dupdd</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#dupdd"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.dupdd" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a3</span> <span class="n">a2</span> <span class="n">a1</span> <span class="o">--</span> <span class="n">a3</span> <span class="n">a3</span> <span class="n">a2</span> <span class="n">a1</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.first">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">first</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#first"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.first" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">([</span><span class="n">a1</span> <span class="o">...</span><span class="mi">1</span><span class="p">]</span> <span class="o">--</span> <span class="n">a1</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.first_two">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">first_two</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#first_two"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.first_two" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">([</span><span class="n">a0</span> <span class="n">a1</span> <span class="o">...</span><span class="mi">0</span><span class="p">]</span> <span class="o">--</span> <span class="n">a0</span> <span class="n">a1</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.fourth">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">fourth</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#fourth"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.fourth" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">([</span><span class="n">a0</span> <span class="n">a1</span> <span class="n">a2</span> <span class="n">a3</span> <span class="o">...</span><span class="mi">0</span><span class="p">]</span> <span class="o">--</span> <span class="n">a3</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.over">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">over</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#over"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.over" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a2</span> <span class="n">a1</span> <span class="o">--</span> <span class="n">a2</span> <span class="n">a1</span> <span class="n">a2</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.pop">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">pop</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#pop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.pop" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a1</span> <span class="o">--</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.popd">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">popd</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#popd"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.popd" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a2</span> <span class="n">a1</span> <span class="o">--</span> <span class="n">a1</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.popdd">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">popdd</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#popdd"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.popdd" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a3</span> <span class="n">a2</span> <span class="n">a1</span> <span class="o">--</span> <span class="n">a2</span> <span class="n">a1</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.popop">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">popop</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#popop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.popop" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a2</span> <span class="n">a1</span> <span class="o">--</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.popopd">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">popopd</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#popopd"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.popopd" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a3</span> <span class="n">a2</span> <span class="n">a1</span> <span class="o">--</span> <span class="n">a1</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.popopdd">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">popopdd</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#popopdd"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.popopdd" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a4</span> <span class="n">a3</span> <span class="n">a2</span> <span class="n">a1</span> <span class="o">--</span> <span class="n">a2</span> <span class="n">a1</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.rest">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">rest</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#rest"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.rest" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">([</span><span class="n">a1</span> <span class="o">...</span><span class="mi">0</span><span class="p">]</span> <span class="o">--</span> <span class="p">[</span><span class="o">...</span><span class="mi">0</span><span class="p">])</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.rolldown">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">rolldown</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#rolldown"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.rolldown" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a1</span> <span class="n">a2</span> <span class="n">a3</span> <span class="o">--</span> <span class="n">a2</span> <span class="n">a3</span> <span class="n">a1</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.rollup">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">rollup</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#rollup"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.rollup" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a1</span> <span class="n">a2</span> <span class="n">a3</span> <span class="o">--</span> <span class="n">a3</span> <span class="n">a1</span> <span class="n">a2</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.rrest">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">rrest</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#rrest"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.rrest" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">([</span><span class="n">a0</span> <span class="n">a1</span> <span class="o">...</span><span class="mi">0</span><span class="p">]</span> <span class="o">--</span> <span class="p">[</span><span class="o">...</span><span class="mi">0</span><span class="p">])</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.second">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">second</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#second"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.second" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">([</span><span class="n">a0</span> <span class="n">a1</span> <span class="o">...</span><span class="mi">0</span><span class="p">]</span> <span class="o">--</span> <span class="n">a1</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.stack">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">stack</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#stack"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.stack" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="o">...</span> <span class="o">--</span> <span class="o">...</span> <span class="p">[</span><span class="o">...</span><span class="p">])</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.stuncons">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">stuncons</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#stuncons"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.stuncons" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="o">...</span> <span class="n">a0</span> <span class="o">--</span> <span class="o">...</span> <span class="n">a0</span> <span class="n">a0</span> <span class="p">[</span><span class="o">...</span><span class="p">])</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.stununcons">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">stununcons</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#stununcons"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.stununcons" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="o">...</span> <span class="n">a1</span> <span class="n">a0</span> <span class="o">--</span> <span class="o">...</span> <span class="n">a1</span> <span class="n">a0</span> <span class="n">a0</span> <span class="n">a1</span> <span class="p">[</span><span class="o">...</span><span class="p">])</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.swap">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">swap</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#swap"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.swap" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a1</span> <span class="n">a2</span> <span class="o">--</span> <span class="n">a2</span> <span class="n">a1</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.swons">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">swons</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#swons"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.swons" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">([</span><span class="o">...</span><span class="mi">0</span><span class="p">]</span> <span class="n">a0</span> <span class="o">--</span> <span class="p">[</span><span class="n">a0</span> <span class="o">...</span><span class="mi">0</span><span class="p">])</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.third">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">third</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#third"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.third" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">([</span><span class="n">a0</span> <span class="n">a1</span> <span class="n">a2</span> <span class="o">...</span><span class="mi">0</span><span class="p">]</span> <span class="o">--</span> <span class="n">a2</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.tuck">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">tuck</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#tuck"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.tuck" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a2</span> <span class="n">a1</span> <span class="o">--</span> <span class="n">a1</span> <span class="n">a2</span> <span class="n">a1</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.uncons">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">uncons</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#uncons"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.uncons" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">([</span><span class="n">a1</span> <span class="o">...</span><span class="mi">0</span><span class="p">]</span> <span class="o">--</span> <span class="n">a1</span> <span class="p">[</span><span class="o">...</span><span class="mi">0</span><span class="p">])</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="joy.utils.generated_library.unswons">
|
||||
<code class="descclassname">joy.utils.generated_library.</code><code class="descname">unswons</code><span class="sig-paren">(</span><em>stack</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/utils/generated_library.html#unswons"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#joy.utils.generated_library.unswons" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">([</span><span class="n">a0</span> <span class="o">...</span><span class="mi">0</span><span class="p">]</span> <span class="o">--</span> <span class="p">[</span><span class="o">...</span><span class="mi">0</span><span class="p">]</span> <span class="n">a0</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -837,6 +950,7 @@ from each list. The smallest list sets the length of the result list.</p>
|
|||
<ul>
|
||||
<li><a class="reference internal" href="#">Function Reference</a><ul>
|
||||
<li><a class="reference internal" href="#module-joy.library"><code class="docutils literal notranslate"><span class="pre">joy.library</span></code></a></li>
|
||||
<li><a class="reference internal" href="#module-joy.utils.generated_library">Auto-generated Functions</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
||||
<link rel="index" title="Index" href="../genindex.html" />
|
||||
<link rel="search" title="Search" href="../search.html" />
|
||||
<link rel="next" title="Replacing Functions in the Dictionary" href="Replacing.html" />
|
||||
<link rel="next" title="Quadratic formula" href="Quadratic.html" />
|
||||
<link rel="prev" title="Essays about Programming in Joy" href="index.html" />
|
||||
|
||||
<link rel="stylesheet" href="../_static/custom.css" type="text/css" />
|
||||
|
|
@ -689,7 +689,7 @@ is just:</p>
|
|||
<li><a href="../index.html">Documentation overview</a><ul>
|
||||
<li><a href="index.html">Essays about Programming in Joy</a><ul>
|
||||
<li>Previous: <a href="index.html" title="previous chapter">Essays about Programming in Joy</a></li>
|
||||
<li>Next: <a href="Replacing.html" title="next chapter">Replacing Functions in the Dictionary</a></li>
|
||||
<li>Next: <a href="Quadratic.html" title="next chapter">Quadratic formula</a></li>
|
||||
</ul></li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
<link rel="index" title="Index" href="../genindex.html" />
|
||||
<link rel="search" title="Search" href="../search.html" />
|
||||
<link rel="next" title="Categorical Programming" href="Categorical.html" />
|
||||
<link rel="prev" title="Traversing Datastructures with Zippers" href="Zipper.html" />
|
||||
<link rel="prev" title="Type Inference" href="Types.html" />
|
||||
|
||||
<link rel="stylesheet" href="../_static/custom.css" type="text/css" />
|
||||
|
||||
|
|
@ -67,7 +67,7 @@
|
|||
<ul>
|
||||
<li><a href="../index.html">Documentation overview</a><ul>
|
||||
<li><a href="index.html">Essays about Programming in Joy</a><ul>
|
||||
<li>Previous: <a href="Zipper.html" title="previous chapter">Traversing Datastructures with Zippers</a></li>
|
||||
<li>Previous: <a href="Types.html" title="previous chapter">Type Inference</a></li>
|
||||
<li>Next: <a href="Categorical.html" title="next chapter">Categorical Programming</a></li>
|
||||
</ul></li>
|
||||
</ul></li>
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -65,6 +65,11 @@
|
|||
<td>   
|
||||
<a href="parser.html#module-joy.parser"><code class="xref">joy.parser</code></a></td><td>
|
||||
<em></em></td></tr>
|
||||
<tr class="cg-1">
|
||||
<td></td>
|
||||
<td>   
|
||||
<a href="library.html#module-joy.utils.generated_library"><code class="xref">joy.utils.generated_library</code></a></td><td>
|
||||
<em></em></td></tr>
|
||||
<tr class="cg-1">
|
||||
<td></td>
|
||||
<td>   
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -11,3 +11,9 @@ Function Reference
|
|||
:members:
|
||||
|
||||
|
||||
Auto-generated Functions
|
||||
---------------------------
|
||||
|
||||
.. automodule:: joy.utils.generated_library
|
||||
:members:
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,365 @@
|
|||
# GENERATED FILE. DO NOT EDIT.
|
||||
|
||||
|
||||
def _Tree_add_Ee(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
([a3 a4 ...0] a2 a1 a0 -- [a1 a2 ...0])
|
||||
|
||||
"""
|
||||
(a0, (a1, (a2, ((a3, (a4, s0)), s1)))) = stack
|
||||
return ((a1, (a2, s0)), s1)
|
||||
|
||||
|
||||
def _Tree_delete_R0(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
([a1 ...0] a0 -- [a1 ...0] a1 a0 a0)
|
||||
|
||||
"""
|
||||
(a0, ((a1, s0), s1)) = stack
|
||||
return (a0, (a0, (a1, ((a1, s0), s1))))
|
||||
|
||||
|
||||
def _Tree_delete_clear_stuff(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(a2 a1 [a0 ...0] -- [...0])
|
||||
|
||||
"""
|
||||
((a0, s0), (a1, (a2, s1))) = stack
|
||||
return (s0, s1)
|
||||
|
||||
|
||||
def _Tree_get_E(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
([a2 a3 ...0] a1 a0 -- a3)
|
||||
|
||||
"""
|
||||
(a0, (a1, ((a2, (a3, s0)), s1))) = stack
|
||||
return (a3, s1)
|
||||
|
||||
|
||||
def ccons(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(a1 a0 [...0] -- [a1 a0 ...0])
|
||||
|
||||
"""
|
||||
(s0, (a0, (a1, s1))) = stack
|
||||
return ((a1, (a0, s0)), s1)
|
||||
|
||||
|
||||
def cons(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(a1 [...0] -- [a1 ...0])
|
||||
|
||||
"""
|
||||
(s0, (a1, s23)) = stack
|
||||
return ((a1, s0), s23)
|
||||
|
||||
|
||||
def dup(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(a1 -- a1 a1)
|
||||
|
||||
"""
|
||||
(a1, s23) = stack
|
||||
return (a1, (a1, s23))
|
||||
|
||||
|
||||
def dupd(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(a2 a1 -- a2 a2 a1)
|
||||
|
||||
"""
|
||||
(a1, (a2, s23)) = stack
|
||||
return (a1, (a2, (a2, s23)))
|
||||
|
||||
|
||||
def dupdd(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(a3 a2 a1 -- a3 a3 a2 a1)
|
||||
|
||||
"""
|
||||
(a1, (a2, (a3, s23))) = stack
|
||||
return (a1, (a2, (a3, (a3, s23))))
|
||||
|
||||
|
||||
def first(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
([a1 ...1] -- a1)
|
||||
|
||||
"""
|
||||
((a1, s1), s23) = stack
|
||||
return (a1, s23)
|
||||
|
||||
|
||||
def first_two(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
([a0 a1 ...0] -- a0 a1)
|
||||
|
||||
"""
|
||||
((a0, (a1, s0)), s1) = stack
|
||||
return (a1, (a0, s1))
|
||||
|
||||
|
||||
def fourth(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
([a0 a1 a2 a3 ...0] -- a3)
|
||||
|
||||
"""
|
||||
((a0, (a1, (a2, (a3, s0)))), s1) = stack
|
||||
return (a3, s1)
|
||||
|
||||
|
||||
def over(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(a2 a1 -- a2 a1 a2)
|
||||
|
||||
"""
|
||||
(a1, (a2, s23)) = stack
|
||||
return (a2, (a1, (a2, s23)))
|
||||
|
||||
|
||||
def pop(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(a1 --)
|
||||
|
||||
"""
|
||||
(a1, s23) = stack
|
||||
return s23
|
||||
|
||||
|
||||
def popd(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(a2 a1 -- a1)
|
||||
|
||||
"""
|
||||
(a1, (a2, s23)) = stack
|
||||
return (a1, s23)
|
||||
|
||||
|
||||
def popdd(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(a3 a2 a1 -- a2 a1)
|
||||
|
||||
"""
|
||||
(a1, (a2, (a3, s23))) = stack
|
||||
return (a1, (a2, s23))
|
||||
|
||||
|
||||
def popop(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(a2 a1 --)
|
||||
|
||||
"""
|
||||
(a1, (a2, s23)) = stack
|
||||
return s23
|
||||
|
||||
|
||||
def popopd(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(a3 a2 a1 -- a1)
|
||||
|
||||
"""
|
||||
(a1, (a2, (a3, s23))) = stack
|
||||
return (a1, s23)
|
||||
|
||||
|
||||
def popopdd(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(a4 a3 a2 a1 -- a2 a1)
|
||||
|
||||
"""
|
||||
(a1, (a2, (a3, (a4, s23)))) = stack
|
||||
return (a1, (a2, s23))
|
||||
|
||||
|
||||
def rest(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
([a1 ...0] -- [...0])
|
||||
|
||||
"""
|
||||
((a1, s0), s23) = stack
|
||||
return (s0, s23)
|
||||
|
||||
|
||||
def rolldown(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(a1 a2 a3 -- a2 a3 a1)
|
||||
|
||||
"""
|
||||
(a3, (a2, (a1, s23))) = stack
|
||||
return (a1, (a3, (a2, s23)))
|
||||
|
||||
|
||||
def rollup(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(a1 a2 a3 -- a3 a1 a2)
|
||||
|
||||
"""
|
||||
(a3, (a2, (a1, s23))) = stack
|
||||
return (a2, (a1, (a3, s23)))
|
||||
|
||||
|
||||
def rrest(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
([a0 a1 ...0] -- [...0])
|
||||
|
||||
"""
|
||||
((a0, (a1, s0)), s1) = stack
|
||||
return (s0, s1)
|
||||
|
||||
|
||||
def second(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
([a0 a1 ...0] -- a1)
|
||||
|
||||
"""
|
||||
((a0, (a1, s0)), s1) = stack
|
||||
return (a1, s1)
|
||||
|
||||
|
||||
def stack(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(... -- ... [...])
|
||||
|
||||
"""
|
||||
s0 = stack
|
||||
return (s0, s0)
|
||||
|
||||
|
||||
def stuncons(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(... a0 -- ... a0 a0 [...])
|
||||
|
||||
"""
|
||||
(a0, s0) = stack
|
||||
return (s0, (a0, (a0, s0)))
|
||||
|
||||
|
||||
def stununcons(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(... a1 a0 -- ... a1 a0 a0 a1 [...])
|
||||
|
||||
"""
|
||||
(a0, (a1, s0)) = stack
|
||||
return (s0, (a1, (a0, (a0, (a1, s0)))))
|
||||
|
||||
|
||||
def swap(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(a1 a2 -- a2 a1)
|
||||
|
||||
"""
|
||||
(a2, (a1, s23)) = stack
|
||||
return (a1, (a2, s23))
|
||||
|
||||
|
||||
def swons(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
([...0] a0 -- [a0 ...0])
|
||||
|
||||
"""
|
||||
(a0, (s0, s1)) = stack
|
||||
return ((a0, s0), s1)
|
||||
|
||||
|
||||
def third(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
([a0 a1 a2 ...0] -- a2)
|
||||
|
||||
"""
|
||||
((a0, (a1, (a2, s0))), s1) = stack
|
||||
return (a2, s1)
|
||||
|
||||
|
||||
def tuck(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
(a2 a1 -- a1 a2 a1)
|
||||
|
||||
"""
|
||||
(a1, (a2, s23)) = stack
|
||||
return (a1, (a2, (a1, s23)))
|
||||
|
||||
|
||||
def uncons(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
([a1 ...0] -- a1 [...0])
|
||||
|
||||
"""
|
||||
((a1, s0), s23) = stack
|
||||
return (s0, (a1, s23))
|
||||
|
||||
|
||||
def unswons(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
([a0 ...0] -- [...0] a0)
|
||||
|
||||
"""
|
||||
((a0, s0), s1) = stack
|
||||
return (a0, (s0, s1))
|
||||
|
||||
|
|
@ -0,0 +1,297 @@
|
|||
from collections import Counter
|
||||
from itertools import imap
|
||||
|
||||
|
||||
class AnyJoyType(object):
|
||||
|
||||
prefix = 'a'
|
||||
|
||||
def __init__(self, number):
|
||||
self.number = number
|
||||
|
||||
def __repr__(self):
|
||||
return self.prefix + str(self.number)
|
||||
|
||||
def __eq__(self, other):
|
||||
return (
|
||||
isinstance(other, self.__class__)
|
||||
and other.prefix == self.prefix
|
||||
and other.number == self.number
|
||||
)
|
||||
|
||||
def __ge__(self, other):
|
||||
return issubclass(other.__class__, self.__class__)
|
||||
|
||||
def __add__(self, other):
|
||||
return self.__class__(self.number + other)
|
||||
__radd__ = __add__
|
||||
|
||||
def __hash__(self):
|
||||
return hash(repr(self))
|
||||
|
||||
|
||||
class NumberJoyType(AnyJoyType): prefix = 'n'
|
||||
class FloatJoyType(NumberJoyType): prefix = 'f'
|
||||
class IntJoyType(FloatJoyType): prefix = 'i'
|
||||
|
||||
class StackJoyType(AnyJoyType): prefix = 's'
|
||||
|
||||
_R = range(10)
|
||||
A = a0, a1, a2, a3, a4, a5, a6, a7, a8, a9 = map(AnyJoyType, _R)
|
||||
N = n0, n1, n2, n3, n4, n5, n6, n7, n8, n9 = map(NumberJoyType, _R)
|
||||
S = s0, s1, s2, s3, s4, s5, s6, s7, s8, s9 = map(StackJoyType, _R)
|
||||
|
||||
|
||||
def update(s, term):
|
||||
if not isinstance(term, tuple):
|
||||
return s.get(term, term)
|
||||
return tuple(update(s, inner) for inner in term)
|
||||
|
||||
|
||||
def relabel(left, right):
|
||||
return left, _1000(right)
|
||||
|
||||
|
||||
def _1000(right):
|
||||
if not isinstance(right, tuple):
|
||||
return 1000 + right
|
||||
return tuple(_1000(n) for n in right)
|
||||
|
||||
|
||||
def delabel(f, seen=None, c=None):
|
||||
if seen is None:
|
||||
assert c is None
|
||||
seen, c = {}, Counter()
|
||||
|
||||
try:
|
||||
return seen[f]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
if not isinstance(f, tuple):
|
||||
seen[f] = f.__class__(c[f.prefix])
|
||||
c[f.prefix] += 1
|
||||
return seen[f]
|
||||
|
||||
return tuple(delabel(inner, seen, c) for inner in f)
|
||||
|
||||
|
||||
def stack_concat(q, e):
|
||||
return (q[0], stack_concat(q[1], e)) if q else e
|
||||
|
||||
|
||||
def unify(u, v, s=None):
|
||||
if s is None:
|
||||
s = {}
|
||||
elif s:
|
||||
u = update(s, u)
|
||||
v = update(s, v)
|
||||
|
||||
if u == v:
|
||||
return s
|
||||
|
||||
if isinstance(u, AnyJoyType) and isinstance(v, AnyJoyType):
|
||||
if u >= v:
|
||||
s[u] = v
|
||||
return s
|
||||
if v >= u:
|
||||
s[v] = u
|
||||
return s
|
||||
raise ValueError('Cannot unify %r and %r.' % (u, v))
|
||||
|
||||
if isinstance(u, tuple) and isinstance(v, tuple):
|
||||
if len(u) != len(v) != 2:
|
||||
raise ValueError(repr((u, v)))
|
||||
for uu, vv in zip(u, v):
|
||||
s = unify(uu, vv, s)
|
||||
if s == False: # (instead of a substitution dict.)
|
||||
break
|
||||
return s
|
||||
|
||||
if isinstance(v, tuple):
|
||||
if not stacky(u):
|
||||
raise ValueError('Cannot unify %r and %r.' % (u, v))
|
||||
s[u] = v
|
||||
return s
|
||||
|
||||
if isinstance(u, tuple):
|
||||
if not stacky(v):
|
||||
raise ValueError('Cannot unify %r and %r.' % (v, u))
|
||||
s[v] = u
|
||||
return s
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def stacky(thing):
|
||||
return thing.__class__ in {AnyJoyType, StackJoyType}
|
||||
|
||||
|
||||
def compose(f, g):
|
||||
(f_in, f_out), (g_in, g_out) = f, g
|
||||
|
||||
if not g_in:
|
||||
fg_in, fg_out = f_in, stack_concat(g_out, f_out)
|
||||
elif not f_out:
|
||||
fg_in, fg_out = stack_concat(f_in, g_in), g_out
|
||||
else:
|
||||
s = unify(g_in, f_out)
|
||||
if s == False: # s can also be the empty dict, which is ok.
|
||||
raise TypeError('Cannot unify %r and %r.' % (fo, gi))
|
||||
fg_in, fg_out = update(s, (f_in, g_out))
|
||||
|
||||
return fg_in, fg_out
|
||||
|
||||
|
||||
def _C(f, g):
|
||||
f, g = relabel(f, g)
|
||||
fg = compose(f, g)
|
||||
return delabel(fg)
|
||||
|
||||
|
||||
def C(*functions):
|
||||
return reduce(_C, functions)
|
||||
|
||||
|
||||
def compilable(f):
|
||||
return isinstance(f, tuple) and all(imap(compilable, f)) or stacky(f)
|
||||
|
||||
|
||||
def doc_from_stack_effect(inputs, outputs):
|
||||
switch = [False] # Do we need to display the '...' for the rest of the main stack?
|
||||
i, o = _f(inputs, switch), _f(outputs, switch)
|
||||
if switch[0]:
|
||||
i.append('...')
|
||||
o.append('...')
|
||||
return '(%s--%s)' % (
|
||||
' '.join(reversed([''] + i)),
|
||||
' '.join(reversed(o + [''])),
|
||||
)
|
||||
|
||||
|
||||
def _f(term, switch):
|
||||
a = []
|
||||
while term and isinstance(term, tuple):
|
||||
item, term = term
|
||||
a.append(item)
|
||||
assert isinstance(term, StackJoyType), repr(term)
|
||||
a = [_to_str(i, term, switch) for i in a]
|
||||
return a
|
||||
|
||||
|
||||
def _to_str(term, stack, switch):
|
||||
if not isinstance(term, tuple):
|
||||
if term == stack:
|
||||
switch[0] = True
|
||||
return '[...]'
|
||||
return (
|
||||
'[...%i]' % term.number
|
||||
if isinstance(term, StackJoyType)
|
||||
else str(term)
|
||||
)
|
||||
|
||||
a = []
|
||||
while term and isinstance(term, tuple):
|
||||
item, term = term
|
||||
a.append(_to_str(item, stack, switch))
|
||||
assert isinstance(term, StackJoyType), repr(term)
|
||||
if term == stack:
|
||||
switch[0] = True
|
||||
end = '...'
|
||||
else:
|
||||
end = '...%i' % term.number
|
||||
a.append(end)
|
||||
return '[%s]' % ' '.join(a)
|
||||
|
||||
|
||||
def compile_(name, f, doc=None):
|
||||
i, o = f
|
||||
if doc is None:
|
||||
doc = doc_from_stack_effect(i, o)
|
||||
return '''def %s(stack):
|
||||
"""
|
||||
::
|
||||
|
||||
%s
|
||||
|
||||
"""
|
||||
%s = stack
|
||||
return %s''' % (name, doc, i, o)
|
||||
|
||||
|
||||
def __(*seq):
|
||||
stack = StackJoyType(23)
|
||||
for item in seq: stack = item, stack
|
||||
return stack
|
||||
|
||||
|
||||
def defs():
|
||||
rolldown = __(a1, a2, a3), __(a2, a3, a1)
|
||||
rollup = __(a1, a2, a3), __(a3, a1, a2)
|
||||
pop = __(a1), __()
|
||||
popop = __(a2, a1,), __()
|
||||
popd = __(a2, a1,), __(a1)
|
||||
popdd = __(a3, a2, a1,), __(a2, a1,)
|
||||
popopd = __(a3, a2, a1,), __(a1)
|
||||
popopdd = __(a4, a3, a2, a1,), __(a2, a1)
|
||||
swap = __(a1, a2), __(a2, a1)
|
||||
rest = __((a1, s0),), __(s0,)
|
||||
rrest = C(rest, rest)
|
||||
cons = __(a1, s0), __((a1, s0),)
|
||||
ccons = C(cons, cons)
|
||||
uncons = __((a1, s0),), __(a1, s0)
|
||||
unswons = C(uncons, swap)
|
||||
swons = C(swap, cons)
|
||||
dup = __(a1,), __(a1, a1)
|
||||
dupd = __(a2, a1), __(a2, a2, a1)
|
||||
dupdd = __(a3, a2, a1), __(a3, a3, a2, a1)
|
||||
first = __((a1, s1),), __(a1,)
|
||||
second = C(rest, first)
|
||||
third = C(rest, second)
|
||||
fourth = C(rest, third)
|
||||
tuck = __(a2, a1), __(a1, a2, a1)
|
||||
over = __(a2, a1), __(a2, a1, a2)
|
||||
stack = s0, (s0, s0)
|
||||
stuncons = C(stack, uncons)
|
||||
stununcons = C(stack, uncons, uncons)
|
||||
first_two = C(uncons, uncons, pop)
|
||||
|
||||
mul = __(n1, n2), __(n3,)
|
||||
sqrt = C(dup, mul)
|
||||
succ = pred = __(n1,), __(n2,)
|
||||
divmod_ = pm = __(n2, n1), __(n4, n3)
|
||||
|
||||
_Tree_add_Ee = C(pop, swap, rolldown, rrest, ccons)
|
||||
_Tree_get_E = C(popop, second)
|
||||
_Tree_delete_clear_stuff = C(rollup, popop, rest)
|
||||
_Tree_delete_R0 = C(over, first, swap, dup)
|
||||
|
||||
return locals()
|
||||
|
||||
|
||||
DEFS = defs()
|
||||
|
||||
#globals().update(DEFS)
|
||||
|
||||
|
||||
def show():
|
||||
for name, stack_effect_comment in sorted(DEFS.iteritems()):
|
||||
t = ' *'[compilable(stack_effect_comment)]
|
||||
print name, '=', doc_from_stack_effect(*stack_effect_comment), t
|
||||
|
||||
|
||||
def generate_library_code(f=None):
|
||||
if f is None:
|
||||
import sys
|
||||
f = sys.stdout
|
||||
print >> f, '# GENERATED FILE. DO NOT EDIT.\n'
|
||||
for name, stack_effect_comment in sorted(DEFS.iteritems()):
|
||||
if not compilable(stack_effect_comment):
|
||||
continue
|
||||
print >> f
|
||||
print >> f, compile_(name, stack_effect_comment)
|
||||
print >> f
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
show()
|
||||
Loading…
Reference in New Issue