Filling Pseq with array

The Pseq has square brackets for an an array
We can also do this , in the dur lane , or just insert a single value
Issue I am having I want 8 times 0.128 and 4 times 0.256

		\pitch, Prand([60,72],inf),

Issue I am having I want 8 times 0.128 and 4 times 0.256 both using the shortcut ! method but it doesn’t work when eclosing them in square brackets , because we will then have an array in an array

I wonder why this doesn’t’ work


There are other ways but if you just want a flat array, there’s none in SC faster than this.

Comma separated expressions in parentheses may only be used as method call argument lists. They don’t combine into a single expression.

(Here, it might be said, “but what about (1, 2 .. 10)?” … but that’s not strictly comma separated. The .. syntax distinguishes series notation from an argument list.)



[0.256!4, 0.128!8].flatten

you can also compose Pseqs FYI

Pseq([ Pseq([0.256], 4), Pseq([0.128], 8)])

I also like concatenation for this:

0.256!4 ++ (0.128!8) Array | SuperCollider 3.12.2 Help

Though the one thing with this is that the parentheses are necessary due to the order in which SC evaluates, from left to right, without preference for order of operations.

Why is there no exclamation mark in your composing example ?

sorry I forgot the brackets!

Pseq([1], 4) is equivalent to Pseq([1,1,1,1],1)
Pseq([1], 8) is equivalent to Pseq( [1,1,1,1,1,1,1,1], 1)

So Pseq([ Pseq([1], 4), Pseq([2], 3) ], 4) is equivalent to

Pseq([ 1,1,1,1,2,2,2],4)

Definitely looks like a lot of typing to get that result but there are some cool things you can do with nested and concatenated patterns

also to avoid needing parens you can also use .dup() instead of !

flat(1.dup(3) ++ 2.dup(4)) // [1,1,1,2,2,2,2]

I don’t understand why the array is filled ( it does work )
If I just write ([0.256,4) the console gives a nil and no arary is filled
How come the pseq fills it ?
The syntax should be consistent throughout the program , no ?

There is one master syntax in SC:


SC also provides some syntactic sugar - you can also write message(Receiver, arguments) for example, but that’s the root syntax.

Every receiver can respond to messages and arguments differently.

Pseq responds to the message .new with arguments [1] and 4 by building a Pseq with [1] as the list and 4 as the repeats.

When a class is followed immediately by parens, the .new method is implicit.

The other way that parens are used is to indicate to the interpreter expressions to evaluate.

so (3 + 4) is replaced by 7. 2 * (3 + 4) becomes 2 * 7.

(3, 4) by itself is not a valid expression so will throw an error ("what is the value of (3, 4) ? ), but rrand(3,4) means “send the message \rrand to 3 with argument 4”.

So remember: parens after a method name mean method(receiver, arguments), “send message to receiver with arguments”. parens after an object mean anObject(message, arguments) again “send message to an object with arguments”. parens after a Class mean - "send message \new to aClass with arguments. parens by themselves mean “interpreter please evaluate this expression”.

So again Pseq([1],3) means send \new to Pseq with arguments [1] and 3. ([1],3) by itself means nothing and will throw an error

That clarify some things , still don’t understand how the pseq interprets the second argument( 3 in your example) as a repeat.
Appreciate the help , from all of you !

Because Pseq defines it to be such., repeats: 1, offset: 0)

(Shown with default values.)

The argument is named “repeats” and it acts like a number of repeats, so it is consistent here.


1 Like

Also , why is the first argument called a list and not array ?
The both use [ ]

Does it matter? :wink:

The parent class of Pseq is ListPattern, and list is used consistently throughout the subclasses of ListPattern.

But tbh, it doesn’t matter.


About the repeat , I was not talking about the argument after the list like
[. ],inf), meaning infinite repeat of the list
I am aware of the meaning of that argument .
I was reffering to semiquaver’s example
([1],3) that fills a list with 3 one’s , not repeat the list 3 times

semiquaver posted no such example!

They did post an example of the form Pseq([1], 3).

It’s the Pseq that gives meaning to the argument list.

You can’t just leave it out and expect it still to make sense.

([1], 3) is indeed, as semiquaver said, meaningless.

A list of comma-separated expressions, inside ( ), must be an argument list for a method call. They can only be an argument list for a method call. There is no other valid usage for this syntax.


I think it’s worth going over again some of what semiquaver said.

There are exactly two types of actions that occur in SC, and only these two:

  • Variable assignment: x = something.
  • A method call.

That is, (basically) every action in SC is a method call.

Every action is a method call.

If SC is doing something, then it must be happening through a method call. The ONLY exception is a simple variable assignment.

Therefore every action in SC must be understood with respect to the parts of a method call, aka “message send.”

  • Method selector: A method call can be understood as sending a message to an object. The method selector is the message being sent. In 5.rand, the message rand is sent to the integer 5. (There are two implicit method selectors: value for objects and new for classes.)
  • Receiver: The object to which the message is sent. In 5.rand, the receiver is 5.
  • Argument list: A method may optionally accept parameters, given in an argument list.

“Fill a list with 3 one’s” and “repeat the list 3 times” are both actions, and they are not variable assignments. Therefore it is impossible to do them without a method call.

Therefore there must be a receiver and a method selector involved. Apart from variable assignment, there are no exceptions in SC to this principle.

(1 ! 3): method selector = !, receiver = 1, argument = 3. All OK.

Pseq([1], 3): method selector = new (implicitly), receiver = class Pseq, arguments = [1] and 3. All OK.

([1], 3) is an argument list lacking a receiver and a method selector = nonsense.

More generally: every expression in SC that confuses you, look for the receiver, method selector and arguments. Because every operation comes down to these.


1 Like

Side note: I think one can’t really understand SC without learning how classes are written and reading some of the source code in the class library.

It can seem daunting at first. The documentation about Class writing is a little terse!

But it really helps one grok the language! @gentleclockdivider I’d highly recommend you take the plunge and learn a little about how classes and methods are defined. With a little literacy you can often find answers in the source code. And even better write and modify methods and classes for your own use. It definitely takes some patience but it can give you a lot of problem solving tools.

1 Like