Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some form of iterative function for lists? #95

Open
tmhglnd opened this issue Sep 17, 2024 · 0 comments
Open

Some form of iterative function for lists? #95

tmhglnd opened this issue Sep 17, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@tmhglnd
Copy link
Owner

tmhglnd commented Sep 17, 2024

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:

https://mercury-playground.pages.dev/#Ly8gQ2xhcHBpbmcgTXVzaWMgLSBTdGV2ZSBSZWljaCAoMTk3MikKLy8gQW4gYWxnb3JpdGhta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QoKLy8gc29tZSByZXZlcmIgb24gYm90aCBzb3VuZHMKc2V0IGFsbCBmeChyZXZlcmIgMC4zIDIp

@tmhglnd tmhglnd added the enhancement New feature or request label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant