AOP use cases

Anton Vredegoor anton at vredegoor.doge.nl
Thu Apr 22 22:46:05 EDT 2004


"Terry Reedy" <tjreedy at udel.edu> wrote:

>Hmmm.  When I started this reply, I was going to emphasize that 'separating
>concerns' is much less efficient than more directly writing

The problem is *which* concerns are to be separated.

def fgen():
    #generate fibonacci sequence
    a,b = 0,1
    while 1:
        a,b = b,a+b
        yield a

def fib(n, L = [], g = fgen()):
    #interface with fibonacci generator
    if n < 0 :
        return 1
    while len(L) <= n:
        L.append(g.next())
    return L[n]

def test():
    print fib(500)

if __name__=='__main__':
    test()

Anton




More information about the Python-list mailing list