< Back to IRCAM Forum

Question: list function connecting like 1234 ABCD 1A2B3C4D

Hi All,

very new in using OM I need a function which connects two lists like that
(1 2 3 4) (1.1 2.1 3.1 4.2) ------> (1 1.1 2 2.1 3 3.1 4 4.2) maybe someone may help :slight_smile:

(till now found nothing like that in the documentary… but maybe I didn’t saw its so much information there… )

Thanks …

Best,
Lena

hello lena,

i’m really interested in how to do this in openmusic. i tried with omloop to no avail. for the moment you could define an internal lisp function like this:

(lambda (l1 l2) (loop for i in l1  
                      for j in l2  
                      collect i collect j))

please have in mind that this will interleave the two lists but up to the shortest one, leaving out the rest of the elements of the longest list.
hope this helps,
regards,
m.

HiPerti

Thanks for your reply, I am going to try it out and give you feedback, should be work the lists content the same amount of elements.
I am wondering that there is no function in a more easier way…

… If it was not what you were looking for, Just wanted to interlock any 2 lists.
Well you can use interlock. (cf attachment)…

Best
K

lena2.omp (2.1 KB)

Hi,

Here’s another way using mat-trans.

note for Karim: interlock is not working if the 2 lists are equal length. 4ex: (3 5 2) (a b c)

Best,
RC

Patch_mat-trans.omp (2.28 KB)

Good solution RC,
and yes you are right about interlock.
However when using mat-trans and unequal list length adding remove at the end of the flat is recommended. (cf screenshot)

BEst
K

Screenshot_2017-10-22_18-26-08.png

Correction: interlock works with 2 lists of equal length but it doesn’t include last element. Same example (3 5 2) (a b c) will give (3 a 5 b 2) as a result. Is there an explanation for this?

Best,
RC

YEs …
It’s because of the missing last position of the first list. If you add nil at the end of the first list then you can interlock the last elem of the second list (see screenshot). YOu should also remove the nil from the resulting output… However i find your mat-trans solution more elegant and efficient…

Best
K

Screenshot_2017-10-22_18-36-15.png

Thanks a lot RC, that was the solution I was searching for!
ps: and Karim of course thanks for ur welcoming me :wink:

You’re welcome, and thanks Karim for the explanation!
Best,
RC

thanks both RC an Karim for the proper om solution.
regards,
m.