macropy icon indicating copy to clipboard operation
macropy copied to clipboard

Read/write closures

Open jnhnum1 opened this issue 11 years ago • 1 comments

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

jnhnum1 avatar Jun 02 '13 10:06 jnhnum1

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

lihaoyi avatar Jun 02 '13 12:06 lihaoyi