< Back to IRCAM Forum

Group with criteria

Hello everyone,

I am writing to ask for help in learning how to group elements of a list into sublists in accordance with a given criterion. For example: having the list (a 1 a a 2 3 4 a 5) how can I have sublists that group contiguous numbers? To be clear, the result of such an operation on the above list should be: (a (1) a a (2 3 4) a (5)).
I hope I have expressed myself clearly and not to waste your time with questions already asked.

Thank you in advance for your time and a warm greeting.
neo

Hi neo,

Your criteria (test condition) is numberp in this case.

One way to do this is using lisp code like that:

Here is the folder:
ctiteria.zip (1.6 KB)

Best
K

1 Like

Dear Mr. Haddad,

Thank you as usual for your decisive contribution and your speed of intervention. I would be curious to know if there would be a way to achieve the same result with visual programming as well.

Kind regards,
neo

Dear neo,

The lisp code is the only simple way to do so. Unless to create a new method in lisp and use it as a box which again is the same thing. The reason is the push macro in the code, which is only allowed as code.

Best
K

1 Like

Hi Neo,

a bit late to the party but interested on this topic.

I found a way to do it comparing pairs of elements in a recursive way:

Maybe this is not so optimal but it’s using visual programming and it’s fun!

It would be great to know if you or someone else has another solution or maybe optimize this one.

best
rc

1 Like

Dear rc0,

I apologize for the delay in responding. Thank you very much for your willingness to try to solve my problem via visual programming. Can I ask if you can share the patch with me? So I could better confront you and ask more precise questions about certain choices you had made.
Thank you again very much for your solution to my problem.

Best,
neo