tmhglnd / mercury

A minimal and human-readable language and environment for the live coding of algorithmic electronic music.
http://www.timohoogland.com/mercury-livecoding
GNU General Public License v3.0
291 stars 13 forks source link

ring every() argument addition #60

Closed GuillemGongora closed 3 years ago

GuillemGongora commented 3 years ago

An additional argument could be added to every() to set the value of the end padding. For instance:

ring abc(1 2 3 4 5) -> (1 2 3 4 5) ring test every(abc 2 8 1) -> (1 2 3 4 5 1 1 1 1 1 1 1 1 1 1 1)

tmhglnd commented 3 years ago

Good idea. Although I now also think that a replace() function would be nice that allows you to replace all values with another value. Like:

ring vals1 [1 2 3 4 5]

ring vals2 every(abc 2 8)
//=> [1 2 3 4 5 0 0 0 0 0 0 0 0 0 0 0]

// replace all 0's with 1's
ring vals3 replace(vals2 0 1)
//=> [1 2 3 4 5 1 1 1 1 1 1 1 1 1 1 1]
GuillemGongora commented 3 years ago

Both could be useful, because replace might change your original ring:

ring vals1 [1 2 0 4 5]

ring vals2 every(vals1 2 8)
//=> [1 2 0 4 5 0 0 0 0 0 0 0 0 0 0 0]

// replace all 0's with 1's
ring vals3 replace(vals2 0 1)
//=> [1 2 1 4 5 1 1 1 1 1 1 1 1 1 1 1]
tmhglnd commented 3 years ago

Ah yes, did not think about that yet!

tmhglnd commented 3 years ago

Is now included in the latest version as 3rd argument:

ring melody [5 7 3 9 1]
ring phrase every(melody 2 7 12)
print phrase
// => [5 7 3 9 1 12 12 12 12 12 12 12 12 12]