< 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