Group Admins

  • Profile picture of Karim
  • Profile picture of Jean


Public Group active 6 days ago

User group for OpenMusic and computer-aided composition. Visit the Forum for discussions.

Grouping a list into sublists in wich the sum of its elements is a given nu

Author 3 Subscribed Users |
Profile photo of BUCK

Hy everyone,

I’m trying to built this patch for a while now and I think it’s time to give up and ask for help. I think this is a quite simple thing to do but I got stuck in a last procedure.

I want to segment a list into sublists with a special charcteristic: the sum of its elements must be equal to a value that I choose from the beggining.
I built a patch that can do exactly that but only one time. The pacth gives me two outputs: the first sublist result that I want to use (with the right sum of its elemments) and the rest of the main list (that is supposedly to pass trough the function again). That’s where I got stuck! I can’t send this new list again to the beggining of the patch. I gues the answer will be some recursive proccedure but I wasn’t able to do that. I tried but it didn’t work. I went over the tutorials and documentations but the examples weren’t enough for me to understand the concept.

Can someone help me?

Thank you very much!

January 28, 2017 at 02:02 #20544
Profile photo of Karim


If i correctly understood your quest, you will be needing the group-list method it will do exactly what you are looking for.


January 28, 2017 at 14:39 #20551
Profile photo of jmdbrady

Recursion is well documented in the OM-Tutorials, Tutorials 36 to 39.
There is another way of programing recursion see the patches below.

January 28, 2017 at 15:20 #20552
Profile photo of BUCK

Hy Karim,

Actually the group-list method doesn’t work for me in this situation because, if I’m not doing anything wrong, this method groups items accordinly to a list of quantity of elements and not accordinly to the sum of its elements.

Let me give you an example of what I’m trying to do. Imagine I have this list:

(3 3 4 7 4 3 3 3 4 4 7 7 7 4 7 3 4 4 3 3 7 7)

I want to segment it when the sum of its elements get 50, so I would have:

(3 3 4 7 4 3 3 3 4 4 7 5) (2 7 4 7 3 4 4 3 3 7 7)

Observe that the element in “posn-match” 11 had to be divided in a 5 (at the end of the first sublist) and a 2 (at the beggining of the second one) so the proportions of the main list could be maintained.

The thing is, the way I built this patch, I can do that procedure once. Since I’m working with big lists I need a patch that can work trough the main list multiple times.

Do you have any suggestion?

Thank you very much!


January 28, 2017 at 15:57 #20557
Profile photo of BUCK

Hy Jean Michel,

Thank you for your patches, I’ll study them!
And I just found your blog. Lots of interresting articles, locking foward to read them.

All the best to you to


January 28, 2017 at 17:41 #20558
Profile photo of Karim

Got you

here is a lisp code . Put it in the patches folder of OM and THEN launch om

Just call group-max function (option+click in a ptch)
it will do the trick.

I guess it is possible to do it graphically but i believe it will be really hard to.


January 28, 2017 at 18:19 #20559
Profile photo of BUCK

Mr. Karim,

I don’t know how to thank you. That was exactly wat I wanted and it is working perfectly fine. Thank’s a lot again for your generosity.

All the best,


February 1, 2017 at 18:42 #20622

You must be logged in to reply to this topic.

Log in now