slicing a big list into smaller lists based on a search string


    Feb 20 2007 | 2:49 am
    Hi all,
    This seems so easy...yet I've been scratching my head over this problem all day. Maybe others here have some suggestions before I scratch myself bald.
    Let's say I have a big long message like so:
    hippo lion 4 ant 2.3 tiger 0.3 rabbit "happy birthday" 33 0.5
    I want to take the big list and break it up into 3 chunks: hippo lion 4 ant 2.3
    tiger 0.3
    rabbit "happy birthday" 33 0.5
    ...based on the appearance of in the list. I can't use unpack or iter since I don't know for certain the length or type of values that will follow . In other 3rd party options I've been able to find, seems like you need to know the length of the message you want to generate (e.g. slicelist), or parses in a way that won't really work for this application (e.g. Lchunk). Any suggestions on how to tackle this?
    Thanks,
    David

    • Feb 20 2007 | 8:32 am
      like this? using stock objects only...
      /*j
      On 20 Feb 2007, at 03:49, David Beaudry wrote:
      >
      > Hi all,
      > This seems so easy...yet I've been scratching my head over this
      > problem all day. Maybe others here have some suggestions before I
      > scratch myself bald.
    • Feb 20 2007 | 8:38 am
      On 20 Feb 2007, at 03:49, David Beaudry wrote:
      >
      > Let's say I have a big long message like so:
      >
      > hippo lion 4 ant 2.3 tiger 0.3
      > rabbit "happy birthday" 33 0.5
      >
      > I want to take the big list and break it up into 3 chunks:
      > hippo lion 4 ant 2.3
      > tiger 0.3
      > rabbit "happy birthday" 33 0.5
      >
      > ...based on the appearance of in the list. I can't use
      > unpack or iter since I don't know for certain the length or type of
      > values that will follow . In other 3rd party options I've
      > been able to find, seems like you need to know the length of the
      > message you want to generate (e.g. slicelist), or parses in a way
      > that won't really work for this application (e.g. Lchunk). Any
      > suggestions on how to tackle this?
      hi david,
      seems a little awkward to do in max, although you could 'force'
      Lchunk to work for your situation (see patch below).
      but if you really need this output format, i would probably pull out
      some text-based solution.
      a simple javascript function could look like this (hopefully the code
      turns up correctly):
      /********** start script ************/
      var keyword = " ";
      function parse() {
      var a = arrayfromargs(arguments);
      var b = new Array();
      for(i=0; i if( a[i] == keyword ) {
      outlet(0, b);
      b = new Array();
      b.push(keyword);
      }
      else
      b.push(a[i]);
      }
      outlet(0, b);
      }
      /*********** end script ************/
      hope that helps.
      volker
      /**** a patch using Lchunk *****/
    • Feb 20 2007 | 10:49 am
    • Feb 20 2007 | 8:00 pm
      Hi all,
      Thanks for your responses!
      I figured the best method was going to lead me to java/javascript...much thanks for the script, Volker!
      Best,
      David