-
Notifications
You must be signed in to change notification settings - Fork 15
Description
While trying to code the Clapping Music piece from Steve Reich I noticed that Mercury actually lacks some method/function/way to allow creating a list iteratively.
The result of the code is currently this:
// the initial rhythm, played 8 times
list ptn copy([1 1 1 0 1 1 0 1 0 1 1 0] 8)
// the repetitions with shifts for every step
list ptn2 join(ptn rot(ptn -1) rot(ptn -2) rot(ptn -3) rot(ptn -4) rot(ptn -5) rot(ptn -6) rot(ptn -7) rot(ptn -8) rot(ptn -9) rot(ptn -10) rot(ptn -11))
It is clear there is lots of repetition needed in order to be able to rotate the pattern after every 8 duplicates. It would be interesting to see if there is a way to do this without the repetition of the code. For example providing a list on a function argument that would usually only accept a single number could make that function perform it multiple times:
list ptn copy([1 1 1 0 1 1 0 1 0 1 1 0] 8)
list ptn2 join(ptn rot(ptn [-1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11]))
This could be written even shorter, by using the spreadInc()
method:
list ptn copy([1 1 1 0 1 1 0 1 0 1 1 0] 8)
list ptn2 rot(ptn spreadInc(12 0 -11))
Another option is that there is some kind of for()
or iterate()/iter()
method, that performance a function iteratively by putting the value from another list as argument. For example:
list ptn copy([1 1 1 0 1 1 0 1 0 1 1 0] 8)
// performance the function rot() multiple times for every value of the first list
// using i as a placeholder for the value from that list
list ptn2 iter([0 -1 -2 -3 ... -11] rot(ptn i))
The current result of coding the Clapping Music: