Simple (?) recursion problem. Can M4L even do recursion?!

miguel3d's icon

Hi all,
In this simplified version of my patch, I am trying to use an [uzi] recursively, but it won't work. :( I don't necessarily need the [uzi], but I need to be able to do recursion.

Here's a cheesy view of the problem:

.         ______________
         |              |         Clicking the message ["5"] gets...
["5"]   ["2"]           |
   |     /              |         1,2,3,1,2,4,3
   |   /                |
   | /                  |         If [uzi] supported recursion,
[_uzi  _     _ ]        |         then output would be...
            /|          |
          /  |          |         1,2,3,1,2,4,5
        /    |          |
      /      |          |         ...which is what I want.
    /        |          |
  [print]  [select 4]   |
             |__________|

How can I simulate recursion in this example?
Are there M4L objects that *do* support recursion?
Please help!

Thx in advance,
Miguel3d

broc's icon
Max Patch
Copy patch and select New From Clipboard in Max.

It seems that Max objects are generally not designed to handle "recursive calls", but the behavior can be simulated by using multiple instances of the object. Do you think that's a serious limitation in practice?

miguel3d's icon

Hi Broc, thx for replying.

The example above is just a simplification. My actual goal here is to generate a list of all devices on the track, including those in all chains, by traversing the track's device hierarchy recursively. I don't know the depth of the hierarchy beforehand.

Right now I'm trying to simulate using [zl stack], but having trouble. :(

broc's icon

Yes, recursion can generally be simulated/implemented with a stack.
But you may also consider using Javascript for traversing the device hierarchy.