Order of execution

Extension, added to LambdaEnvir:

LazyPbind : Pbind {
	embedInStream { |inevent|
		var proto = Event.new;
		var lambdaEnvir;
		var event;

		// these will become LazyResults later
		// this is OK because both streams and functions respond to 'value'
		patternpairs.pairsDo { |key, value|
			proto.put(key, value.asStream)
		};

		loop {
			if(inevent.isNil) { ^nil.yield };
			// passing 'proto' here populates all the LazyResult objects
			lambdaEnvir = LambdaEnvir(proto)
			.parent_(inevent.parent).proto_(inevent.proto);
			event = inevent.copy;
			lambdaEnvir.keysValuesDo { |key|
				var value = lambdaEnvir[key];  // this is what resolves the LazyResult
				if(value.isNil) { ^inevent };
				if(key.isSequenceableCollection) {
					if(key.size > value.size) {
						("the pattern is not providing enough values to assign to the key set:" + key).warn;
						^inevent
					};
					key.do { |key1, i|
						event.put(key1, value[i]);
					};
				} {
					event.put(key, value);
				};
			};
			inevent = event.yield;
		}
	}
}

// oh, and LambdaEnvir needs to add:
+ LambdaEnvir {
	parent { ^envir.parent }
	proto { ^envir.proto }
	parent_ { |parent| envir.parent_(parent) }
	proto_ { |proto| envir.proto_(proto) }
}

Then:

(
p = LazyPbind(
	\instrument, \default,
	\freq, Pkey(\dur).linexp(0.05, 0.25, 200, 800),
	\dur, Pwhite(0.05, 0.25, inf)
).play;
)

p.stop;

Here’s \freq depending on \dur that is defined later, and… it works.

So… are we onto something here?

hjh

2 Likes