Bubobubobubobubo / sardine

Python's missing "algorave" module. Live code music with Python using MIDI, OSC and/or SuperCollider.
https://sardine.raphaelforment.fr
GNU General Public License v3.0
194 stars 31 forks source link

Swimming Function Definition and Scopes #218

Open Rhoumi opened 1 year ago

Rhoumi commented 1 year ago

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
Bubobubobubobubo commented 1 year ago

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 commented 3 months ago

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.