Recursively (re)define Pdef

Given the following code,


As this plays, I can redefine \x as it goes:

Pdef(\x,Pbind(\note,Pseq([3,2,2]))); \\changes notes while playing

… and access \x as a pattern for something like Padd

Padd(\note,2,Pdef(\x)) \\ if I were to play this, does the thing, but doesn't change what's playing

What I can’t seem to do is redefine \x recursively, i.e. using the environment value of \x, something like

Pdef(\x,Padd(\note,2,Pdef(\x)))  // crashes interpreter :(((

What am I missing?

The Pdef docs give examples of successful and unsuccessful recursion, the idea I guess being that embedInStream needs to not infinitely loop.

This gave me the idea to copy to a new key. This works

Pdef(\x,Padd(\note,2,Pdef(\y))); // succeeds during playback

It’s not terribly elegant but gets the job done. Still wondering if there’s a more elegant way to “eagerly” consume the stream in a single Pdef call, or if some other JITlib-y mechanism would be better.

OK I think the following is the best yet and almost even “not a workaround”:


Again, interested in any other ways to achieve similar results, but source (as seen in PatternProxy.copyState) serves to eagerly resolve Pdef(\x), eliminating the recursion.