Is there a shorter way of writing Pseq([1])?

p{1.yield} is not shorter (and p{1} is obviously always nil-yielding). Interestingly, Array has asPseg but not asPseq, and Number has neither. Basically is there some (shorer) operator that turns a literal array into an Pseq, cutting out some eye sore?

I see I can write PL(1,1) using the PLx extension (its 2nd arg “repeats” defaults to inf so it needs to be explicit).

There are lots of patterns that take a sequence in their constructor, so there aren’t syntactic shortcuts for all of them. If brevity is critical, the best you can do is something like:

+SequenceableCollection { s { |...args| ^Pseq(this, *args) } }

[1, 2, 3].s

It’s quite common for people to build a library of shortcuts like this for their own livecoding practice.

3 Likes

yep, I write [1].q or [1].q(inf) etc

There’s built-in shortcut of sort for this; fin's argument defaults to n = 1 so.

1.fin // -> a Routine
1.fin.all // -> [ 1 ]

If resetting that is necessary, to turn it from a stream into a pattern one can append a .p, but that is not much shorter than a Pn… (styling aside). It does save the hassle of having to remember which of Pn’s arguments is the repeat, relevant in case the constant you want to emit is not 1…

1.fin.p // -> a Prout
Pn(1,1)

Another pattern that defaults to reps 1 is Pfucn.

Pfuncn{1}

but that’s clearly longer to type.

There’s Pfin too, but that’s not very useful here since the count for that comes first (unlike in fin) and thus/also has no default, so easy to get confused…

Pfin(3, 1).iter.all
// -> [ 1, 1, 1 ]
Pn(3, 1).iter.all
// -> [ 3 ]