< Back to IRCAM Forum

Successive Operations On Nested Lists

Hello all, really enjoying using OM and the ability it provides to use a computer to assist in composition (CAC).

Question,

I generate a nested list

((0 1 2)(0 1 2)(0 1 2))

I would like to increment each sublist by an amount (first list by 0, second by 12, third by 24 (12+12))

Desired resultant

((0 1 2)(12 13 14)(24 25 26))

I have tried using mapcar, omloop, and combining those two but cannot get a working solution. My hangup is the incrementing of the value added to each subsequent list.

Naturally these values will be dynamic (list size, number of sublists, and value to increment)

Thank you for your help!

Hi apoorbaugh,

Now if you want to do EXACTLY what you stated:
Screenshot_2022-03-24_21-44-10
Now if you want to do what I suspect you want to do:

And here is the patch:
Patch 7.omp (4.6 KB)

Best
K

1 Like

Thank you @haddad for the quick reply and the solution!

It had not occurred to me to use multiple inputs for both the mapcar or the forloop functions. Didn’t even cross my mind.

Funny enough, I just got home and wrote the same solution as your first one using om loop and the create-list function before checking back on this post.

While they both solve what I was trying to do could you tell me what the main differences are between the two solutions and when you might want to use one over the other?

:peace_symbol: :heart_hands: :slightly_smiling_face:

The second solution outputs more values starting from a simple list while the first does exactly what you described at first.

Best
K