What's wrong with my .pfunc method?

I made this method to save me a tiny bit of typing:

+ Function { pfunc { ^Pfunc({this}); } }

This works:

Pbindef(\a, \degree, {(1..9).choose}.pfunc, \dur, Pwhite(0.1,0.5,inf)).play

This doesnt, error is ‘Message ‘schedBundleArrayOnClock’ not understood.’

Pbindef(\a, \degree, {(1..3).choose}.pfunc, \dur, {(1..3).choose}.pfunc).play

This works:

Pbindef(\a, \degree, {(1..3).choose}.pfunc, \dur, Pfunc({(0.1,0.2..0.5).choose}))

What am I missing here? Thanks!

You’re creating a Pfunc whose function returns this (a function).

+ Function {
	pfunc {
		// in here, 'this' is the function you want to execute
		Pfunc(  // OK
			// now you're writing a function to execute
			// but you already have that function: 'this'
			// so there's no need to declare a new function
			{
				// the function returns 'this' function
				this
			}
		)
	}
}

So then dur is not a number: it’s a function. And the event system indeed doesn’t know what to do with that.

Habit is deadly. You’re used to writing Pfunc({ something }) and so assumed that { } is a necessary part of the syntax. But it’s not about syntax – it’s about semantics. If something is an expression rather than a function, then it needs to be enclosed in braces. If it’s a function itself, then braces only double-function it.

+ Function { pfunc { Pfunc(this) } }

hjh

Thank you James, that’s very clear. It may also have a bearing on another puzzle that I am struggling with at the moment…