< Back to IRCAM Forum

Easy list operation -> list splitting

Hi All,

I need a function to split a list

for axample (a b c d e f)

-> (a c e) ( b d f)

I am sure its very simple but I dont get it at the moment…

if possible please offer me a visual solution :slight_smile: I didnt started with lisp, will do that soon…

Thanks for reply!

All the Best

Hi MariaRose,

You can check the group-list function this should do it.

best
K

…oops ,

sorry no tis won’t do.
see screenshot… (it is not elegant, but will do)

Best
K

Screenshot_2018-07-05_19-25-59.png

Hi Karim

thanks for your fast reply… hmm I dont think thats the right function…
mabye I dont understand the syntax alright but he is only doing that
Ex. (group-list '(1 2 3 4) '(1 3) 'linear) => ((1) (2 3 4))
Ex. (group-list '(1 2 3 4) '(1 2 3) 'linear) => ((1) (2 3) (4))
Ex. (group-list '(1 2 3 4) '(1 2 3) 'circular) => ((1) (2 3) (4 1 2))

but I need

(1 2 3 4 5 6 …) -> (1 3 5 … ) (2 4 6 …)

Best Regards :slight_smile:

-> wrote it before you send the second reply ith screenshot :wink:

ah yes thats it! (there is no elegant solution?.. for long lists :D)

Thank you!!

Best Regards :slight_smile:

Hi,
Indeed Karin is right. For long lists just put a 2 in the segmentation.
(i’m curious about an elegant solution for this)
Best,
RC

Screenshot_2018-07-05_19-46-31.png

Thank you also RC :slight_smile:

Best

Ok,

Here is a generic solution. grouping by n (2 3 etc, …) whatever the list is.
It is not that elegant. In lisp it would be more Zennish!

(cf. Patch)

Best
K

group-by-n.omp (7.57 KB)

Hohohoho !

RC you blew my patching mind… ! I used Om a longtime but didn’t realize that putting an integer in the group-list second arg works in this way!
Thanx this is great !

Best
K

This works in OM - not as elegant as it could be, but I’m just getting back into LISP after 50 years!

(lambda (inlist)
(setq flag t)
(setq outa ())
(setq outb ())
(setq outlist ())
(dolist (in inlist)
(if flag (setq outa (cons in outa))
(setq outb (cons in outb))
)
(setq flag (not flag))
)
(setq outlist (list outa outb)))
)

uhh… I see

I urgently have to start with lisp :wink:

Soon I have some more time left, so I know what to do!

Thanks for all your fast solutions!

Gn8, all the Best <3