Changeset 1761 for lang/unlambda

Show
Ignore:
Timestamp:
11/19/07 01:12:52 (12 months ago)
Author:
nishio
Message:

lang/unlambda/impl/in_python: replace Dot and Apply with lambda

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/unlambda/impl/in_python/unlambda_lambda.py

    r1759 r1761  
    1919>>> run("``.b`.a`ci.c") 
    2020ababc 
    21 >>> Debug.show_node = True 
    22 >>> run("``v.a.a") 
    23 (apply (apply V (print 'a')) (print 'a')) 
    24 (apply V (print 'a')) 
    25 V 
    26 >>> Debug.show_node = False 
    2721>>> run("````skk.av") 
    2822a 
     
    6761I = lambda: lambda c: c(lambda X, c: c(X)) 
    6862 
    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) 
     63import sys 
     64Dot = lambda char: (lambda c: c(lambda X, c: sys.stdout.write(char) or c(X))) 
     65 
     66Apply = 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            ) 
    11378 
    11479class D(Node):