Pbind pairs \key, val, vs *[key:value, key: value] array/collection

I don’t really know where I’ve seen this, but these two both work:

(
Pbind(
    \dur, 1/4,
    \degree, Prand((1..4), inf)
).play;
)

// *[ key: val ] syntax:

(
Pbind(*[
    dur: 1/4,
    degree: Prand((1..4), inf)
]).play;
)

I was just wondering what is this syntax - *[ key: val ] for Pbind and where is it coming from, is there any documentation for it, can it be used elsewhere and are there any drawbacks?

There is a discussion going on about this here: * in Pbind alternative syntax

1 Like

using a star in front of square brackets “peels off” the brackets

example:

(
var mysum = { |a, b| a + b }; // function taking two arguments
mysum.value(5,6).postln; // "normal" way of calling the function
mysum.value(*[5,6]).postln; // equivalent way of calling the function with a list instead of "loose" numbers
mysum.(5,6).postln; // actually the word "value" is optional too
mysum.(*[5,6]).postln; // equivalent
)

In the documentation it is mentioned briefly in the “Symbolic Notations” document (not sure if it appears elsewhere too).

This e.g. makes it easy to programmatically construct arguments to a function as a list.

1 Like