Lists in List and indexing
hi guys,
how can I implement a list in list indexing in maxMsp like in (almost) any programing language:
list myList = [["a,b,c"], ["x","y","z"], ["1","2","3"]]
myList[1]
>> ["x","y","z"]
myList[2][0]
>>"1"
thanks in advance!
I'd use a dictionary for that.
ok.
but how are dict's from the performance side in time critical apps?
are coll's faster? or does it matter at all? :)
The 'Bach' package is quite useful for handling nested lists.
i use conversions between symbols and lists (and usually coll for storage.)
"1 2 3 4 5", "list a b c"
[tosymbol]
[prepend symbol]
"symbol 1 2 3 4 5", "symbol a b c"
then [sprintf], [zl group], [pack zzz zzz] or whatever.
allows 254*254( minus index and commas) characters in max 4 and 254*2096 in max 7 to be written in "one line" or "one parameter".
if you prefer to have a specific writing style such as the one in you example code above you could add that just fine when concatenating the sub-lists with [sprintf]:
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 331 387 120 9109513 [1 2 3] [a b c];
#P newex 331 349 98 9109513 prepend set;
#P newex 331 276 98 9109513 sprintf [%s] [%s];
#P newex 468 208 98 9109513 prepend symbol;
#P newex 468 179 98 9109513 tosymbol;
#P newex 331 208 98 9109513 prepend symbol;
#P newex 331 179 98 9109513 tosymbol;
#P button 401 42 28 0;
#P newex 468 123 98 9109513 list a b c;
#P newex 331 123 98 9109513 1 2 3;
#P connect 4 0 7 0;
#P connect 6 0 7 1;
#P connect 7 0 8 0;
#P connect 8 0 9 0;
#P connect 2 0 0 0;
#P connect 2 0 1 0;
#P connect 0 0 3 0;
#P connect 1 0 5 0;
#P connect 5 0 6 0;
#P connect 3 0 4 0;
#P window clipboard copycount 10;
(i wouldnt use commas and quotation marks in max, we usually only use them on the forums to indicate what is of what type, but in code ussed inside max it is too confusing to read. brackets look great to indicate a sublist IMO.)
@ROMAN wow thanks! it is nice to see how somebody handles stuff! different!
I don't have a specific writing style although as a musician I prefer C/C++ ;)
someday, when I've figured out how to write externals in C++, I'll jump more into coding then dealing with cables.
But I think MAX/PD are great for making fast GUI's and prototyping complex structures!
@BROC Yeah I've looked into the bach package. seems very, very, very complicated. even with the fairly nice help/doc. but what would be the solution with "bach"? a small example would be very kind.
cheers!
with bach:
Hope this helps,
aa
dicts need tremendous amount of RAM if they get large, and symbols never get free'd in max, so both have to be used with care. I'd solve this problem with javascript, unless the small amount of time for the change into the js engine is not acceptable.
@ANDREA thanks! but are there some limitations in M4L with bach? I'm not getting any print output.. or am I mising something?
@HOLLYHOOK oh.. nice to know about RAM issues! thanks
To get the M4L print window: right-click on the device title bar.