<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Setting up a recursive loop in jsl in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Setting-up-a-recursive-loop-in-jsl/m-p/476067#M72063</link>
    <description>&lt;P&gt;I would not use recursion for this. Use a list of WorkToBeDone and a list of WorkCompleted and a flag FoundSomething. Write your loop something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;good = function({ method, item), 
// use the current strategy/method to test the item
// return 1 if pass, 0 if fail
);

FoundSomething = 1; // flag: are we still making progress?
strategy = 1; // maybe change the strategy after each round
while(FoundSomething,
    FoundSomething = 0;
    for(i = nitems(WorkToBeDone), i&amp;gt;=1, i -= 1, // backwards because removing items
        if( good( strategy, WorkToBeDone[i] ),
            insertinto(WorkCompleted, removefrom(WorkToBeDone,i));
            FoundSomething = 1;
        )
    );
    strategy += 1; // new strategy for next round
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 05 Apr 2022 01:12:49 GMT</pubDate>
    <dc:creator>Craige_Hales</dc:creator>
    <dc:date>2022-04-05T01:12:49Z</dc:date>
    <item>
      <title>Setting up a recursive loop in jsl</title>
      <link>https://community.jmp.com/t5/Discussions/Setting-up-a-recursive-loop-in-jsl/m-p/472438#M71714</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've built a long script where a curve fitting is performed iteratively on a large data table&amp;nbsp;&lt;SPAN&gt;which many variables listed in 1 column. However at the end of the process some of those variables are not fitted (the process failed for one reason or another). At this point, I create a 'failed fitting' list of the variables that were not fitted in the previous and create a subset from the source table&amp;nbsp; (select where/contains/subset) and run part of the initial script again (that portion of the script is wrapped in an expression) on the subset table (selected rows, all columns) .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;At the end of the second round of fitting, a new&amp;nbsp; 'failed fitting ' list is created (typically smaller).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to find a way to create a recursive loop where the code would look for the size of the last&amp;nbsp; 'failed fitting' list and if it is greater than 0 and different from the previous&amp;nbsp;'failed fitting' list, it will initiate another round of fitting until the&amp;nbsp;'failed fitting'=0 or is identical to the previous&amp;nbsp;'failed fitting' list ( to avoid creating an infinite loop).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sebastien&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:46:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Setting-up-a-recursive-loop-in-jsl/m-p/472438#M71714</guid>
      <dc:creator>Sburel</dc:creator>
      <dc:date>2023-06-10T23:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: Setting up a recursive loop in jsl</title>
      <link>https://community.jmp.com/t5/Discussions/Setting-up-a-recursive-loop-in-jsl/m-p/472458#M71716</link>
      <description>&lt;P&gt;JMP does provide recursion with Recurse(). I think you can also recall the same function again to make it recursive&lt;/P&gt;
&lt;P&gt;Using recurse():&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
ex rev = Function({s},
	If(Length(s) &amp;lt;= 1,
		s,
		Recurse(Substr(s, 2)) || Left(s, 1)
	)
);
ex rev("abcd");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Calling same function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
ex rev = Function({s},
	If(Length(s) &amp;lt;= 1,
		s,
		ex rev(Substr(s, 2)) || Left(s, 1)
	)
);
ex rev("abcd");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Mar 2022 19:45:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Setting-up-a-recursive-loop-in-jsl/m-p/472458#M71716</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-03-23T19:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: Setting up a recursive loop in jsl</title>
      <link>https://community.jmp.com/t5/Discussions/Setting-up-a-recursive-loop-in-jsl/m-p/472459#M71717</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for the tip. I'll give it a shot&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sebastien&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 19:47:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Setting-up-a-recursive-loop-in-jsl/m-p/472459#M71717</guid>
      <dc:creator>Sburel</dc:creator>
      <dc:date>2022-03-23T19:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: Setting up a recursive loop in jsl</title>
      <link>https://community.jmp.com/t5/Discussions/Setting-up-a-recursive-loop-in-jsl/m-p/476066#M72062</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your original input. Unfortunately, I have not managed to turn your suggestion into a workable script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I'm attaching another description of my objective (not a function script but rather a 'workflow').&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully, someone can point me in the right direction.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sebastien&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
clear log();


sourcefitting={"a","b","c","d","e","f"};
/*The sourcefitting list can be 1000s longs and split in batches to perform some curve fitting, parameter extraction and them summarization using a FOR loo into a master table. 
The process is expected to fail on some of those batches. 
The failed items are identifed/listed into the 'failedfitting" list. 
At which point a recursive loop using 'processX' needs to be implemented to take care of the remaining items using a new round of batching and fitting (for some reason the 'failing' process works on smaller batches but predicting which one will failed is not possible hence the need for a recessive loop), until the 'failedfittingX' list' is either empty or is stagnating (processfitting=1) ie the process keeps on failing and running the process another round is not longer warranted.
 */


processX=expr(/* process XYZ*/ //each time the processX is run 2 list are generated "succesfittingX" and "failedfittingX" are generated

//A new list "successfittingX" is generated at the end of the recursive loop
successfitting0={"a","c","d"};
/*
successfitting1={"a","c","d","b"};
successfitting2={"a","c","d","b","e"};
successfitting3={"a","c","d","b","e","f"}*/;// or successfitting3={"a","c","d","b","e"};
successfitting=successfittingX;

//The successfittingX and the sourcefitting lists are compared and a resulting list "failedfittingX" is created:

failedfitting0={"b","e","f"};
/*
failedfitting1={"e","f"};
failedfitting2={"f"};
failedfitting3={}*/; // or failedfitting3={"f"};
failedfitting=failedfittingX;
failednb=Nitems(failedfitting);
if(failedfittingX==failedfittingX-1,progressfitting=1, progressfitting=0);
);



//The issue is about correctly defining the structure recursive loop which uses the previous list to determine wheter the process needs to keep on going or if it is completed
// the use of the function 'recurse' has been suggested

testrec=function({failednb},
		if(failednb&amp;gt;0&amp;amp;processfitting=0 ,recurse( processX),show("Done"))
);
testrec(failednb);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 00:13:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Setting-up-a-recursive-loop-in-jsl/m-p/476066#M72062</guid>
      <dc:creator>Sburel</dc:creator>
      <dc:date>2022-04-05T00:13:58Z</dc:date>
    </item>
    <item>
      <title>Re: Setting up a recursive loop in jsl</title>
      <link>https://community.jmp.com/t5/Discussions/Setting-up-a-recursive-loop-in-jsl/m-p/476067#M72063</link>
      <description>&lt;P&gt;I would not use recursion for this. Use a list of WorkToBeDone and a list of WorkCompleted and a flag FoundSomething. Write your loop something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;good = function({ method, item), 
// use the current strategy/method to test the item
// return 1 if pass, 0 if fail
);

FoundSomething = 1; // flag: are we still making progress?
strategy = 1; // maybe change the strategy after each round
while(FoundSomething,
    FoundSomething = 0;
    for(i = nitems(WorkToBeDone), i&amp;gt;=1, i -= 1, // backwards because removing items
        if( good( strategy, WorkToBeDone[i] ),
            insertinto(WorkCompleted, removefrom(WorkToBeDone,i));
            FoundSomething = 1;
        )
    );
    strategy += 1; // new strategy for next round
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Apr 2022 01:12:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Setting-up-a-recursive-loop-in-jsl/m-p/476067#M72063</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2022-04-05T01:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: Setting up a recursive loop in jsl</title>
      <link>https://community.jmp.com/t5/Discussions/Setting-up-a-recursive-loop-in-jsl/m-p/476305#M72082</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;&amp;nbsp;Thanks a lot for the suggestion. I will try this strategy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sebastien&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 16:10:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Setting-up-a-recursive-loop-in-jsl/m-p/476305#M72082</guid>
      <dc:creator>Sburel</dc:creator>
      <dc:date>2022-04-05T16:10:06Z</dc:date>
    </item>
  </channel>
</rss>

