Group Admins

  • Profile picture of Karim
  • Profile picture of Jean

OpenMusic

Public Group active 3 hours, 42 minutes ago

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

question: list function connecting like 1234 ABCD 1A2B3C4D

Author 4 Subscribed Users |
Profile photo of MariaRose
MariaRose


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

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

Thanks ..

Best,
Lena

October 22, 2017 at 04:54 #24093
Profile photo of perti
perti

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.

  • This reply was modified 1 month, 3 weeks ago by Profile photo of perti perti.
October 22, 2017 at 15:21 #24099
Profile photo of MariaRose
MariaRose

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

October 22, 2017 at 15:47 #24101
Profile photo of Karim
Karim

… 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

Attachments:
  1. lena2.omp
  2. lena2.omp
October 22, 2017 at 16:39 #24105
Profile photo of rc
rc

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

Attachments:
  1. Screenshot_2017-10-22_17-21-27

    Screenshot_2017-10-22_17-21-27.png

  2. Screenshot_2017-10-22_17-21-27

    Screenshot_2017-10-22_17-21-27.png

  1. Patch_mat-trans.omp
  2. Patch_mat-trans.omp
October 22, 2017 at 17:01 #24108
Profile photo of Karim
Karim

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

Attachments:
  1. Screenshot_2017-10-22_18-26-08

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

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

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

October 22, 2017 at 17:29 #24113
Profile photo of rc
rc

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

October 22, 2017 at 17:30 #24116
Profile photo of Karim
Karim

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

Attachments:
  1. Screenshot_2017-10-22_18-36-15

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

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

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

October 22, 2017 at 17:36 #24117
Profile photo of MariaRose
MariaRose

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

  • This reply was modified 1 month, 3 weeks ago by Profile photo of MariaRose MariaRose.
October 22, 2017 at 17:49 #24120
Profile photo of rc
rc

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

October 22, 2017 at 17:56 #24122
Profile photo of perti
perti

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

October 22, 2017 at 22:28 #24125

You must be logged in to reply to this topic.

Log in now