< Back to IRCAM Forum

'Lookup' function in OM

I was wondering if it’s possible to have a ‘lookup’ function in OM similar to that of Excel, where an index number can be used as a reference to a list and recalled at a later stage?

To give a concrete example:

I’ve been using the ‘r-list-indexer’ LISP function from the OMRuben Library to add an index number to the front each note of a pre-existing MIDI file, and I want to apply various permutations to the index list only, and then recall the MIDI info relating to each index (preserving the pitch, duration and velocity information namely). Basically, reordering the notes.

I’m sure there’s a super-clever way to do this in OM but I’m stumped. Any suggestions very welcome!

Hi hbell25,

Well if you just need to permute the list of events, you can do this without the indexing.
However if you need to index a list of list and for some reason use the index to reorder the list of list, this is completely possible. However not necessary. Where the indexing is interesting is when you need to refer directly to a list of list using the indexes.
For instance:

the patch:
Patch 2.omp (8.1 KB)

Hope this helps

So can you formulate

Hi Karim,

I should have been clearer, I was just using the ‘permut-random’ as an example of a simpler permutation!

The indexing is element is quite essential to the process. I’m hoping to apply quite complex permutations to the indexed list (like the sorting algorithm you helped me with the other day).

I think posn-match might do the trick as demonstrated in your patch.

Could you explain how the LISP car function works? I can’t find it in the function reference guide. I’ve used mapcar quite a bit so I’m guessing it’s similar?


Hi hbell25,

Concerning the car function, well it is not strange you didn’t find in the function reference guide. The reason is that it is a Lisp “primitive”, ie, it is at the basis of the lisp language (cf. CAR and CDR - Wikipedia). In OM, you have most of the lisp language functions available.

What car does is simply take the head of a list. Its counterpart is the cdr primitive which returns the rest of the list. And so ‘first’ function is equivalent to ‘car’. The ‘rest’ function is equivalent to cdr. And all these are available in OM.

The exception are what we call macros that are most of them not available as graphic ““functions””. However you can call them in the lisp repl. Their equivalent like loop is omloop, etc.


Thanks for explaining, that makes a lot of sense as there are quite a few lisp functions I’ve come across which aren’t in the reference guide. Is there are resource you can recommend for learning/referencing Lisp primitives?

Also re. the original post, the posn-match worked perfectly in the end.

You can see here: