List length of indices and values

leaozinho's icon

I have a list composed of indices and values (e.g. "0 1, 1 3, 2 5") that I want to find the length of and output that number. So for this example the answer would be "3". Is this possible? With the given example "zl len" keeps giving me "2."

Nate S's icon

Hey! The problem here seems to be your commas; rather than being a separator, Max, it seems, treats them as coordinates. "0 1, 1" comes out with a length of 1, but "3, 2 5" apparently has a length of 2. Weird.

Regardless, I'd use quotations, rather than commas, to separate values. ""0 1""1 3""2 5"" comes out with a length of three. Alternatively, if you have the bach external, you could use lllls (with brackets instead of commas).

Hope this helps!

DK's icon

Max treats messages in comma-separated lists as individual messages sent sequentially. "0 1, 1 3, 2 5" is the equivalent of three messages: [0 1], [1 3], and [2 5] sent one right after the other. Each of these lists is, obviously, 2 elements long. This is also why Nate is seeing the "weird" behavior. If you hook up the output to a print object, you'll see the output for each of the lists.

Wrapping your value pairs in quotation marks, either manually or via [tosymbol] before packing them into a list without commas should get you what you want.

Bill 2's icon

Or, without commas, [zl len] -> [/ 2]

Or, with commas:

Max Patch
Copy patch and select New From Clipboard in Max.

Wetterberg's icon

this is the simplest one I can come up with that also solves it to 3

Simply feed it to coll and ask it "length".

Max Patch
Copy patch and select New From Clipboard in Max.