tag:support.nodebox.net,2012-11-01:/discussions/show-your-work/195-the-green-dot-square-puzzleNodeBox: Discussion 2017-05-11T08:48:46Ztag:support.nodebox.net,2012-11-01:Comment/424605782017-05-02T18:07:18Z2017-05-02T18:07:18ZThe Green Dot Square Puzzle<div><p>This is super-cool. Also, it looks really good (both the network and the view :-)</p></div>Frederik De Blesertag:support.nodebox.net,2012-11-01:Comment/424605782017-05-02T22:26:30Z2017-05-02T22:26:30ZThe Green Dot Square Puzzle<div><p>Thanks, Frederik!</p>
<p>I sure wish NodeBox could do recursion. My "AddCombo" nodes come tantalizingly close, but I still have to manually add K-1 nodes myself.</p>
<p>If you look at my "Conway's Game of Life" network, you will see that I managed some recursion by writing each generation to the hard disk (using a custom node) and then reading what I wrote. This was a kludgey way to sneak some state into NodeBox's stateless world. I think you once talked about a "monad" to hold a speck of state to support recursion in a similar, less kludgey way.</p>
<p>How hard would it be to add recursion to NodeBox?</p>
<p>John</p></div>johntag:support.nodebox.net,2012-11-01:Comment/424605782017-05-03T06:42:04Z2017-05-03T06:42:04ZThe Green Dot Square Puzzle<div><p>In NodeBox Live, we now have stateLoad / stateSave nodes that — as the names suggest — load and save state. We use these for feedback networks, useful to <a href="https://nodebox.live/tutorial/g5particles">simulate particles</a>, for example.</p>
<p>Would that help for recursion?</p></div>Frederik De Blesertag:support.nodebox.net,2012-11-01:Comment/424605782017-05-03T09:02:09Z2017-05-03T09:13:36ZThe Green Dot Square Puzzle<div><p>Frederik,</p>
<p>Almost, but not quite.</p>
<p>A simple example of recursion is the factorial function:</p>
<p>function factorial ( n ) :<br>
if n < 2 then return 1 else return n * factorial ( n - 1 )</p>
<p>I have attached a mockup of how such a function might be implemented in NodeBox (see screenshot).</p>
<p>The screenshot shows a subnetwork called factorial which takes a single (integer) parameter n and returns n! The compare node tests whether n < 2. If true (1), the switch is set to 1. If false (0), the switch is set to n * me ( n-1 ).</p>
<p>This is all perfectly normal except for the node called "me". Me would be a special node that could only be used inside another subnetwork. Me would simply stand in for its parent. It would have the same number of parameters as its parent (sprouting new parameter ports automatically whenever its parent was altered).</p>
<p>If you could provide us with this magic "me" node, NodeBox would then be able to do recursion and a whole new continent of possibilities would open up.</p>
<p>stateLoad and stateSave, if I understand them correctly, would at least make a factorial function possible, but I believe that in order to use them you would have to hit play.</p>
<p>You could feed a frame node and an n value into a subnetwork which would then check to see whether frame > n. If so it would return the saved value. Otherwise it would retrieve the state from the previous frame, multiply that by the current frame value, and store the result in the state.</p>
<p>This would sort of work, but you'd have to "crank" it by hitting play until the recursion was complete. I don't want to have to hit play just to calculate a factorial.</p>
<p>Hard hard would it be to add a "me" node to NodeBox?</p></div>johntag:support.nodebox.net,2012-11-01:Comment/424605782017-05-03T14:09:09Z2017-05-03T14:09:09ZThe Green Dot Square Puzzle<div><p>great example John, so you make a list with every 4 elements combination, then check lengths... a cross node would be nice to help make the list</p>
<p>about recursion, for string replacement it would be handy to be able to work with lists too (and concatenate could have 7 inputs like combine btw)</p></div>riochtag:support.nodebox.net,2012-11-01:Comment/424605782017-05-11T08:48:16Z2017-05-11T08:48:46ZThe Green Dot Square Puzzle<div><p>Hi Frederik,</p>
<p>Are you still there?</p>
<p>I am curious what you think of my proposal for a "me" node. Is it feasible?</p>
<p>I am working on another project right now that really needs recursion.</p>
<p>John</p></div>john