sardine icon indicating copy to clipboard operation
sardine copied to clipboard

Swimming Function Definition and Scopes

Open Rhoumi opened this issue 1 year ago • 2 comments

Example to understand the issue :

def intro():
    @swim
    def test(p=0.5,i=0):
        D("bd",i=i)
        again(test,p=0.5,i=i+1)

intro() #calling the swimming function inside intro()

silence(test) #doesn't silence test

Rhoumi avatar May 09 '23 20:05 Rhoumi

This is indeed a bug. I don't really know what to do with it. I should probably take care of keeping reference to all asyncrunners in a data structure somewhere. Not urgent for the moment but if more people start to use similar patterns, I'll try to update and fix.

Bubobubobubobubo avatar May 14 '23 12:05 Bubobubobubobubo

This is not really an issue but has to do with the scope of function definition. See the following:

def intro():
    @swim
    def test(p=0.5,i=0):
        D("bd",i=i)
        again(test,p=0.5,i=i+1)
    return test

my_runner = intro()

This example returns the function in the main scope. However, it is true that this runner is now special in the sense that it is not available as a global variable. There is probably a clever hack to implement but I wasn't able to find it.. yet.

Bubobubobubobubo avatar Jun 17 '24 07:06 Bubobubobubobubo