Question about Concatenating Values to Form an Array

Hello,

I’m trying to create an array that has numerous entries are are all the same value. I’m trying to instantiate it without typing out some repetitive data.

This is in a pattern, so I’d rather not use .do or .collect or something like that.

The array I’d like to create, for example is:

[0.9, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3] 

However, if it write:

0.9 ++ 0.3 ! 6

or even:

0.9 ++ 0.3.dup(6)

I receive an error:

ERROR: Message '++' not understood.

I’ve tried sticking parens around stuff in various combinations, but I still get the same error.

What’s throwing me off though is that having the values in the opposite order works fine. This gives me the array that I want:

0.3 ! 6 ++ 0.9

Does anyone know why it works one way, but the other?

Also, can anyone recommend a different way to quickly create an array like this?

Thanks!
Boris

I think in your first example 0.9 isn’t yet an array so you can’t concatenate

0.9.asArray ++ 0.3

returns [ 0.9, 0.3 ]

but then because of order of operations

0.9.asArray ++ 0.3 ! 6

makes [ [ 0.9, 0.3 ], [ 0.9, 0.3 ], [ 0.9, 0.3 ], [ 0.9, 0.3 ], [ 0.9, 0.3 ], [ 0.9, 0.3 ] ]

so you’d need

[0.9] ++ (0.3 ! 6)
//or
0.9.asArray ++ (0.3 ! 6)

EDIT: in your reversed example the 0.3!6 makes an array first, so you can concatenate

Ahh, that makes total sense. Thank you!

just because this an area of sclang i cherish

[9]++(3!6)
[9].addAll(3!6)
(3!6).addFirst(9)
(3).dup(6).addFirst(9)

cheers,
eddi
https://alln4tural.bandcamp.com

2 Likes

and don’t forget

1.bubble ++ 3

semiquaver wrote:

and don’t forget

1.bubble ++ 3

What’s the etymology of that method? It’s a fun name, but I almost thought you were joking until I tried it!

(edit: not sure how to quote you properly…)

perhaps its because enclosing an array (or int) in an array looks like putting it inside a bubble [[[ ! ]]]

check out this fun mind-bending corner of SC:

http://doc.sccode.org/Guides/J-concepts-in-SC.html

4.bubble == [4]
[4].bubble == [[4]]
[3,4].bubble == [[3,4]]
[[3,4]].unbubble == [3.4]
etc

I end up using these (and flop) rather often…

There are so many little nooks in the documentation!

Lots of interesting and useful methods in there.

I really appreciate the multitude of ways it’s possible to do things in SC, and the ways it’s possible to be inconsistent with things like parentheses around curly brackets, etc.

Like in a spoken language, each person can have their apply their own slang, quirks, cadences, etc.