# Sytax for pattern inside a regular array?

What is the syntax for putting a pattern inside a regular array?

This is the idea:

``````Pbind(\degree, [0, Pseq([2,4,6],inf)]).play;
``````

Doesn’t throw an error, but the pattern doesn’t sound, I hear only the `0`, I expected to hear a chord of `0` and one of the values inside the pattern.

This is not the regular way of writing patterns. The normal way would be something like:

``````Pbind(\degree, Pseq( [0, Pseq([2,4,6],inf), inf)]).play;
``````

and you could use any other Pattern that takes the array as argument, such as Prand or Pser. plus use another number of repeats than inf.

Patterns are designed so that you can nest patterns inside of patterns. But they must be patterns, not arrays.

Iannis

Thanks. But that is not what I’m trying to achieve.
Your code plays: `0, 2, 4, 6, 2, 4, 6, 2, 4, ...`.
What I’m aiming for is to play: `[0,2], [0,4], [0,6], [0,2], [0,4], ...`

One solution would be:

``````Pbind(\degree, Pseq([[0,2],[0,4], [0,6]],inf)).play
``````

but I was wondering if there is a simpler way to get the same result.
Any ideas?

You can use Ptuple in this situation:

`Pbind(\degree, Ptuple([0, Pseq([2,4,6],inf)],inf)).play`

1 Like

Ah, yes! Thanks @vmx. That’s what I was looking for!

As the first component is not sequenced a further alternative would be collecting.

``````Pbind(\degree, Pseq([2,4,6],inf).collect { |i| [0, i] }).play

// or shorter

Pbind(\degree, Pseq([2,4,6],inf).collect([0,_])).play
``````
1 Like

hum… that’s an interesting one. Thanks @dkmayer!

Thread resurrection, only because this happens to look rather cool syntax-wise with my recent experiment/invention Pforai; it basically says "take the zero (as a stream of zeros) and pair each value/zero with every item from the [2, 4, 6] array. The combine/merging function `[_,_]` in this case is just “merging” by pariing into a 2-element array:

``````Pbind(\degree, Pforai(0, [2, 4, 6], [_,_])).trace.play;
``````

The array for Pforai can be a pattern or stream too, i.e the row can change after a full previous row is “done”. For immediate swap I have a Pforp variant

``````Pbind(\degree, Pforp(0, Pseq([2, 4, 6]), [_,_])).trace.play;
``````

Merely for combining arrays by interleaving there’s actually `Place` in the standard library, but here you also have to [P]clump the result:

``````Pbind(\degree, Place([0, [2, 4, 6]], inf).clump(2)).trace.play
``````

`Place` doesn’t take patterns for the array, but there’s `Ppatlace` which does.

Also worth a mention

``````Pbind(\degree, Pbinop(\pair, 0, Pseq([2, 4, 6], inf))).trace.play; //or
Pbind(\degree, Pbinop(\pair, 0, Pseq([2, 4, 6]), 'x')).trace.play;
``````

since there are many more methods defined than Psomethings, if you can find a method already defined that does what you want but isn’t “patternized” you can just the above technique. (Although in this case you do have Ptuple.) There’s an Event-based hack that allows one to use Pbinop with arbitrary functions as pseudo-operators, but it’s seldom worth it, when you can use Pcollect etc. which take functions as input.

1 Like