Changeset 1751 for lang/unlambda
- Timestamp:
- 11/18/07 21:17:43 (6 years ago)
- Files:
-
- 1 modified
-
lang/unlambda/impl/in_python/unlambda.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/unlambda/impl/in_python/unlambda.py
r1749 r1751 4 4 >>> run("`.ai") 5 5 a 6 >>> run("``i.ai") 7 a 8 >>> run("`i`.ai") 9 a 10 >>> run("`d`.ai") 11 >>> run("``d`.aii") 12 a 13 >>> run("`.b`i`.ai") 14 ab 15 >>> run("`.b`d`.ai") 16 b 17 >>> run("``.b`d`.aii") 18 ba 19 """ 6 20 7 """8 globals().clear()9 21 # Main loop 10 22 # … … 30 42 def EvalTask(node, cont): 31 43 def run(): 44 #print node 32 45 return node.eval(cont) 33 46 return run … … 40 53 class I(Node): 41 54 "identity" 55 def __str__(self): 56 return "I" 42 57 def eval(self, cont): 43 58 def I0(X, cont): 44 return cont .invoke(X)59 return cont(X) 45 60 return cont(I0) 46 61 … … 49 64 def __init__(self, c): 50 65 self.c = c 66 def __str__(self): 67 return "(print %r)" % self.c 51 68 def eval(self, cont): 52 69 def Dot0(X, cont): … … 62 79 self.nX = X 63 80 self.nY = Y 81 def __str__(self): 82 return "(apply %s %s)" % (self.nX, self.nY) 64 83 def eval(self, cont): 65 84 nY = self.nY … … 68 87 "evalated X and not-evaluated Y" 69 88 70 # if X.isDelay: 71 # return self.cont.invoke(D1Function(self.nY)) 89 if X.__class__ == D: 90 def Promise0(Y, cont): 91 def next(X): 92 def Promise1(X, cont): 93 return X(Y, cont) 94 return cont(Promise1) 95 return nY.eval(next) 96 return cont(Promise0) 72 97 73 98 def next(Y): … … 78 103 return _App1 79 104 return EvalTask(self.nX, next) 80 105 106 class D(Node): 107 def __str__(self): 108 return "D" 109 def eval(self, cont): 110 return cont(self) 111 def __call__(self, Y, cont): 112 raise NotImplemented 113 81 114 def _parse(iter): 82 115 c = iter.next() … … 85 118 ".": lambda: Dot(iter.next()), 86 119 "`": lambda: (lambda f=_parse(iter): Apply(f, _parse(iter)))(), 120 "r": lambda: Dor("\n"), 121 "d": lambda: D(), # special form 87 122 88 "r": lambda: R(),89 123 "v": lambda: V(), 90 "d": lambda: "(delay)", # special form91 124 "c": lambda: C(), 92 125 "s": lambda: S(), … … 103 136 doctest.testmod() 104 137 105 run("`.ai")
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)