Changeset 1689 for lang/unlambda
 Timestamp:
 11/17/07 02:03:23 (8 years ago)
 Files:

 1 modified
Legend:
 Unmodified
 Added
 Removed

lang/unlambda/impl/in_python/unlambda.py
r1688 r1689 22 22 23 23 class Apply(Node): 24 "apply: `FG = F(G)" 24 25 def __init__(self, f, g): 25 26 self.f = f 26 27 self.g = g 27 28 def eval(self): 28 return self.f.eval()(self.g.eval()) 29 f, g = self.f, self.g 30 if f == "(delay)": # special form 31 def Promise0(Y): 32 g.eval() 33 def Promise1(X): 34 return X(Y) 35 return Promise1 36 return Promise0 37 return f.eval()(g.eval()) 29 38 30 39 class Dot(Node): 40 "print char: `.aX => print 'a'" 31 41 def __init__(self, c): 32 42 self.c = c … … 35 45 import sys 36 46 sys.stdout.write(self.c) 47 return X 37 48 return Dot0 38 49 39 50 class R(Node): 51 "carriage return: `rX => newline" 40 52 def eval(self): 41 53 def R0(X): 42 54 print 55 return X 43 56 return R0 44 57 45 58 class K(Node): 59 "constant: ``kXY = X" 46 60 def eval(self): 47 61 def K0(X): … … 52 66 53 67 class S(Node): 68 "substitution: ```sXYZ = ``XZ`YZ" 54 69 def eval(self): 55 70 def S0(X): … … 62 77 63 78 class I(Node): 79 "identity" 64 80 def eval(self): 65 81 def I0(X): … … 68 84 69 85 class V(Node): 70 """ blackhole: v(x) == v86 """void: v(x) == v 71 87 equivalent to ` ``s``s`kskk ``s``s`kskk""" 72 88 def eval(self): … … 85 101 "r": lambda: R(), 86 102 "v": lambda: V(), 103 "d": lambda: "(delay)", # special form 87 104 }.get(c, lambda: _parse(iter))() 88 105 return result