Group Admins

  • Profile picture of Karim
  • Profile picture of Jean

OpenMusic

Public Group active 15 hours, 40 minutes ago

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

easy list operation -> list splitting

Author 4 Subscribed Users |
Profile photo of MariaRose
MariaRose

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 :) I didnt started with lisp, will do that soon..

Thanks for reply!

All the Best

July 5, 2018 at 17:56 #27061
Profile photo of Karim
Karim

Hi MariaRose,

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

best
K

July 5, 2018 at 18:20 #27062
Profile photo of Karim
Karim

…oops ,

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

Best
K

Attachments:
  1. Screenshot_2018-07-05_19-25-59

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

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

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

July 5, 2018 at 18:26 #27063
Profile photo of MariaRose
MariaRose

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 :)

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

  • This reply was modified 4 months, 1 week ago by Profile photo of MariaRose MariaRose.
July 5, 2018 at 18:33 #27066
Profile photo of MariaRose
MariaRose

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

Thank you!!

Best Regards :)

July 5, 2018 at 18:37 #27067
Profile photo of rc
rc

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

Attachments:
  1. Screenshot_2018-07-05_19-46-31

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

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

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

July 5, 2018 at 18:51 #27070
Profile photo of MariaRose
MariaRose

Thank you also RC :)

Best

July 5, 2018 at 18:52 #27073
Profile photo of Karim
Karim

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

July 5, 2018 at 19:02 #27074
Profile photo of Karim
Karim

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

July 5, 2018 at 19:06 #27077
Profile photo of WindFromWest
WindFromWest

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)))
)

July 5, 2018 at 19:18 #27078
Profile photo of MariaRose
MariaRose

uhh.. I see

I urgently have to start with lisp 😉

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

Thanks for all your fast solutions!

Gn8, all the Best <3

July 6, 2018 at 00:25 #27083

You must be logged in to reply to this topic.

Log in now