 # Using Computed List from Output as Input

Hi all,

Learning more about loops and how to efficiently utilize them. Something is stumping me however. I would like to use the list that is output from a function as the input for the same function when it is run again. I would like to iterate this function for say 20 times using the output from the previous ‘generation’ as the input to calculate the next ‘generation.’

For example;

``````Input -> (0 5 8)
[
Function
Calculate the difference between successive numbers (0 5 8) -> (5 3)
Reverse that list (5 3) -> (3 5)
Create series using those values starting from LAST number in list (8) + 3 + 5 -> (8 11 16)
]
Output -> (8 11 16)
``````

NOW

Use that output list as the input into the function and run it again;

``````Input -> (8 11 16)
[
Function
Calculate the difference between successive numbers (8 11 16) -> (3 5)
Reverse that list (3 5) -> (5 3)
Create series using those values starting from LAST number in list (16) + 5 + 3 -> (16 21 24)
]
Output -> (16 21 24)
``````

Continue for another 19 generations outputting the list each time.

I can do this by stacking multiple instances of the same function but this doesn’t really feel like the most efficient or ‘right’ way to implement this. I have a feeling that the accumulator needs to be used in an loop but I cannot figure out how to set it up without getting the “Impossible to connect, this would create a cycle” error.

I have attached my basic implementation as explained above (list flip add) and the actual problem that I am working on (Retrograde Interval Link).

Any suggestions are very welcome! Dear apoorbaugh,

Loop is an amazing macro which omloop is based on. So it is quite easy to implement what you are looking for using it’s accum object:

You can than again use the same for the Donatoni process:

Only thing I added was an extra input for your patch which is passed as a function, and it should be a binary function (ie. with 2 inputs, even if the second one is unused.) This is the pattern to use with omloop whenenver you want to do an operation recursively on its output.

Here is the patch:
Patch.omp (17.3 KB)

Best
K

1 Like

Karim,

Thank you as always for sharing your knowledge and the expedient reply! I am amazed with the simplicity of this solution.I have seen the unused second input on a lambda-function patch before but didn’t know quite what it was used for.

Only thing I added was an extra input for your patch which is passed as a function, and it should be a binary function

Could you explain a little more how this unused inlet is parsed by omloop and accum? Is it just a signifier that you want to use to function recursively? I see also that there is no input for the first inlet on accum - is this related to the lambda function?

Blockquote

Well these two issues are related.
The second extra input takes values from the first iterated values of the first input of accum if needed. There is an old tutorial about this here:
http://recherche.ircam.fr/equipes/repmus/OpenMusic/user-doc/DocFiles/Tutorial/tut036/Index.html

Best
K