Forums > Max For Live

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

December 29, 2013 | 3:47 pm

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


December 30, 2013 | 1:58 am

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?

<code>

– Pasted Max Patch, click to expand. –

</code>


December 30, 2013 | 2:40 am

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. :(


December 30, 2013 | 3:27 am

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


Viewing 4 posts - 1 through 4 (of 4 total)