Substitute single number in a list
I am trying to figure out how to substitute a single number in a defined list. For example, you start with a list of 200 zeros. You also have an index of a specific zero within that list and the number you want to replace it with. In addition, each time you replace a single zero with a number, everything else in the list must return to zero.
I have found out a way to do this with route, but it is very inefficient and I was hoping that there was a better way.
I have created this patch as an example of what I am trying to accomplish. This does what I want, I was just hoping there was a more efficient way to achieve the same goal
With very long lists I would use coll.
or Multislider
1. set incoming list to pak
2. set changes to individual elements to pak (using a [gate 255] or similar lego tech)
3. trigger result from pak
(using pak only works when data type is known and length is fixed)
The only sane workaround making up for Max's lack of a proper list storage/manipulation object is the super-hidden 2nd inlet feature of [zl mth/nth]:
Here's a flexible way of doing it using one of Max's sane storage/manipulation objects ;-) (just send appropriate size messages to [table] and [group])
@JG: copy/paste error? Your patch is the same as above....
Whoops! Thanks, Diemo. Here's the right one:
One more vote for zl.rot!
If you can live with lists of size >= 2, containing only integers, and some extra patching to get the whole list then, sure, you could call [table] sane (at least relative to the thicket Max has organically grown into during the last 30 years =-)
@diemo - isn't a list < 2 just a number? :-) I take the point re. integers; I guess you could do some trickery with multiplying before the table and dividing after it, but that's a bit fussy. You could also use [capture], tho' that again is fussier than [table].
@Pedro - that trick with [zl.rot] is very nice!of size
And agreed, Max has become quite a thicket - I often wonder if it couldn't be tidied up a bit. Re. the extra patching after [table]: I don't see it as extra - given one's use case, you may want the numbers out of table as a list or as a series of separate numbers; the system is flexible, hence a bit more complicated.
isn't a list < 2 just a number?
No, it isn't.
It is a list of length 1, or of length zero, the latter being something that is impossible to represent concisely in Max, without setting flags and handling special cases all the way through. (See this discussion https://www.facebook.com/groups/maxmspjitter/permalink/10159143189409392/)
And agreed, Max has become quite a thicket - I often wonder if it couldn't be tidied up a bit.
That thicket grows its roots in backwards compatibility, which is something we all cherish and depend upon... (Cycling is doing a great job in this respect, shielding us from the upgrade hell of OSes, apps and frameworks.)
One way out of the thicket is to use a proper programming language, like JavaScript, another to use well-crafted packages for sane data-handling, such as MuBu... (ahem)