lihaoyi / macropy

Macros in Python: quasiquotes, case classes, LINQ and more!
3.28k stars 178 forks source link

Read/write closures #48

Open jnhnum1 opened 11 years ago

jnhnum1 commented 11 years ago

Generators can handle this particular example, but it would be nice if we could use this style of programming:

@closures
def makeCounter():
    x = 0
    def foo():
        x += 1
        return x
    return foo

which would be transformed into

def makeCounter():
     x = [0]
     def foo():
         x[0] += 1
         return x[0]
     return foo
lihaoyi commented 11 years ago

We would probably need basic static analysis (https://github.com/lihaoyi/macropy/issues/44) in order to keep track of scoping and make sure it's the same variable we're assigning too