| 69 | | class Dot(Node): |
| 70 | | "print char: `.aX => print 'a'" |
| 71 | | def __init__(self, c): |
| 72 | | self.c = c |
| 73 | | def __str__(self): |
| 74 | | return "(print %r)" % self.c |
| 75 | | def __call__(self, cont): |
| 76 | | def Dot0(X, cont): |
| 77 | | import sys |
| 78 | | sys.stdout.write(self.c) |
| 79 | | return cont(X) |
| 80 | | return cont(Dot0) |
| 81 | | |
| 82 | | class Apply(Node): |
| 83 | | "apply: `FG = F(G)" |
| 84 | | def __init__(self, X, Y): |
| 85 | | "take 2 not-evaluated node" |
| 86 | | self.nX = X |
| 87 | | self.nY = Y |
| 88 | | def __str__(self): |
| 89 | | return "(apply %s %s)" % (self.nX, self.nY) |
| 90 | | def __call__(self, cont): |
| 91 | | nY = self.nY |
| 92 | | def next(X): |
| 93 | | def _App1(): # task |
| 94 | | "evalated X and not-evaluated Y" |
| 95 | | |
| 96 | | if X.__class__ == D: |
| 97 | | def Promise0(Y, cont): |
| 98 | | def next(X): |
| 99 | | def Promise1(X, cont): |
| 100 | | return X(Y, cont) |
| 101 | | return cont(Promise1) |
| 102 | | return nY(next) |
| 103 | | return cont(Promise0) |
| 104 | | |
| 105 | | def next(Y): |
| 106 | | def _App2(): # task |
| 107 | | "evaluated X and Y" |
| 108 | | return X(Y, cont) |
| 109 | | return _App2 |
| 110 | | return nY(next) |
| 111 | | return _App1 |
| 112 | | return EvalTask(self.nX, next) |
| | 63 | import sys |
| | 64 | Dot = lambda char: (lambda c: c(lambda X, c: sys.stdout.write(char) or c(X))) |
| | 65 | |
| | 66 | Apply = lambda nX,nY:\ |
| | 67 | lambda c:\ |
| | 68 | EvalTask(nX, |
| | 69 | lambda X:\ |
| | 70 | lambda:\ |
| | 71 | (X.__class__ == D)and( |
| | 72 | c(lambda Y,c:nY(lambda X:c(lambda X,c:X(Y,c)))) |
| | 73 | )or( |
| | 74 | nY(lambda Y: lambda :X(Y, c)) |
| | 75 | ) |
| | 76 | |
| | 77 | ) |