< Back to IRCAM Forum

Beginner's Q: transform list "m d f..." to "10 6 4 ..."

Dear all friends,

I have a question about how to transform a list.

if I value 20 letters (discrete) like that (the numbers could be arbitrary):
p = 13; s = 16; d = 3; c = 2 q = 14; v = 18; y = 20; r = 15; h = 7; n = 12; t = 17; f = 5; a = 1; w = 19; l = 10; e = 4; m = 11; g = 6; i = 8; k = 9;

how can I transform a list:
(M A A I N T K V K K A V I P V A G L G T R M L P A T K A I P K E M L P L V D K P L I Q Y V V N E C I A A G I T E I V L V T H S S K N S I E N H F D T S F E L E A M L E K R V K R Q L L D E V Q S I C P P H V T I M Q V R Q G L A K G L G H A V L C A H P V V G D E P V A V I L P D …

to

(11 1 1 8 12 17 9 18 …

—————————————————

I have a similar question like:

  1. there is a list of list, includes 4 lists:

((n 6900 250) (a 7200 2000) (s 7100 250) (e 6500 1000))

  1. there is another list of letters:

(n s e a s s n)

  1. I want the result like:
    ((6900 250) (7100 250) (6500 1000) (7200 2000) (7100 250) (7100 250) (6900 250))

How can I do?

Thanks a lot!

Best wishes,

Ye

Hi Ye,

Here is a patch that will do what you want. However, it is not case sensitive, i.e E = e

Best
K

ye1.omp (5.64 KB)

Thank you Karim!

The patch solves my problem, thank you!
The lisp function “assoc” really works well.

I have a question of study:

like “assoc” or “substitute” or “replace”, etc. How can I find these functions if I don’t know the name of them? Is it somewhere in the library? And, it seems there hasn’t Documentation (online of offline) about them.

Maybe I just don’t know how to find and study them?

Thanks again for your help.

Best regards,

Ye

Hi Ye,

These functions are standard CommonLisp functions You will find them here :

https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node1.html#SECTION00100000000000000000

Which is the Main reference of Clos.

However I warn you, this is really hard to read as a book. My advice is to look into it as if it was a reference.

A tip, when you don’t get a documentation in OM for a function (while hitting ‘d’), like , list, nth or the kind, this means it is a native function of CommonLisp, so not in OM particular code nor in a Library…

Have fun

Best
K

Dear Karim,

Thanks a lot! Yes the Clos looks really cool, and awful! But it’s efficient to use the index, thank for your advice, too!

Have a good evening

Bests,

Ye