list acrobatics ...

    Jul 22 2011 | 10:34 am
    Hi all,
    While trying to max with these things myself, I just wondered if anyone have done the following before:
    1) reversing a selected part of a list from element x to x 2) offsetting part of a list from element x to x (overwrite the original list with the offset part) 3) repeating part x to x of a list right after the selected part (overwrite the original list with the repeated part)
    I will post my solutions below this post, (if) _when_ hopefully I figure it out myself, but until then, some help from more experienced max users is very much appreciated :-)

    • Jul 22 2011 | 12:05 pm
      Here's how to do number 1)
    • Jul 22 2011 | 12:11 pm
      Hah! You pipped me to it, Kaspar. However, I discovered some odd behaviour while knocking together an example patch (I can guess why it's happening, but I would consider it a bug).
      See what you reckon:
    • Jul 22 2011 | 12:26 pm
      Hi christripledot, and thanks for your post :-)
      Here's how I discovered I could do 3) repeating part x to x of a list right after the selected part (overwrite the original list with the repeated part)
    • Jul 22 2011 | 1:12 pm
      my version of all three. Similar to yours Kaspar. I used rotate for the offset one. Not sure if that's what your after but it does what it's supposed to I guess. It looks a bit cumbersome but... works?
    • Jul 22 2011 | 1:27 pm
      Hey both,
      Sorry I'm at work so can't pore over your patches, but I noticed in example 1 (the reverser), in both of your solutions, it doesn't work if the start index is 0, cos nothing comes out the left of [zl slice]. It can be bodged, of that I'm sure, but I can't see a clean way to do it and le bosshog is looking over my shoulder... I suspect similar issues affect examples 2 and 3...
      This sort of thing gets surprisingly tricky, make sure to test thoroughly!
    • Jul 22 2011 | 1:46 pm
      i did this a lot when making a copy function for 8 patterns each with a 64 step/10slots matrix where you could copy any length from anywhere to anywhere - but without zl (using counters and colls). its been my third max patch back then and it was quite hard to learn about max own timing and problems with iteration. zl is the better choice in most cases, but is there any way to say "look up a list for a value of x and send out the index"?
    • Jul 22 2011 | 2:26 pm
      If you want to get Really Serious about list-processing:
      (hint: what does "LISP" stand for?) :-)
      It works well, I used it a lot in this project:
    • Jul 22 2011 | 2:44 pm
      @christripledot - the first index of zl is 1 except in the case of mth and lookup where the first index is 0. So 0 does not work with rev because there is no index zero. This is the expected behaviour, is that correct?
    • Jul 22 2011 | 2:52 pm
      @xh9o - i am not sure with zl but in the LObjects library there is Lfind which finds the first matching value and outputs the index. You might be able to do it with zl but I am not so sure how.
    • Jul 22 2011 | 4:39 pm
      --->but is there any way to say "look up a list for a value of x and send out the index"?
      you can do this with [zl sub], just use a single value for the right inlet. Then you determine the index by the offset that comes out of the right outlet. It also gives you the total number of elements found.
    • Jul 22 2011 | 10:09 pm
      great, thank you!
    • Jul 26 2011 | 8:36 am
      Hi all,
      and great to see the discussion that has been going on. Back from a weekend trip, I now post my own offest patch, where I don't use [zl rotate], because it affects the entire list and also the first values of the list. I want to avoid that, and this is how I do it:
      ... yes, I agree, all of the above experiments need to be tested. Not in all cases do they work properly.
    • Jul 26 2011 | 8:43 am
      comment to the above post: sometimes the list is longer, but it doesn't matter in the patch I use it. I just cut the last bits off the list :-) For some, however, this may be a problem.
    • Jul 26 2011 | 2:35 pm
      @christripledot: The behavior is because list is a reserved keyword, like int, float, symbol and bang. (though you could use these in this example because those are all valid members of a list)
    • Jul 26 2011 | 2:37 pm
      Also, you could use mxj to do all of these quite easily. The Collections API will do most of the work for you; ArrayList is what you want.