<?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 Functional Programming with JSL, Anyone? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/46994#M26782</link>
    <description>&lt;P&gt;Does anyone write&amp;nbsp;JSL using functional programming, and if so do you have a standard set of functions that you use?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As an example, the&amp;nbsp;simplified map function below does all of the work of a for loop so you only need to specify an expression and a list and the function returns a list with the function evaluted for each element. In R, a similar function and variants of it can be found in the package &lt;A href="https://cran.r-project.org/web/packages/purrr/purrr.pdf" target="_self"&gt;'purrr'&lt;/A&gt; by Lionel Henry&amp;nbsp;and Hadley Wickham.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// A function to evaluate an expression for each item in a list
// 
// x__   A list
// fn__  An expression containing ___ (three underscores) that
//       is replaced with each element of x__
//
// Returns a list the same length as x__.
//
map = function( {x__, fn__},
	r__ = {};
	for(i__ = 1, i__ &amp;lt;= N items( x__ ), i__++,
		r__ = Insert( r__, Eval( substitute(Name Expr( fn__ ), Expr(___), Expr( x__[i__] ) ) ) );
	);
	return(r__);
);

//Data to evaluate
vals = { 1, 2, 3, -3, -2, 0.5, -1.1, 5.3, 2.7, 0 };

//number of entries above zero
map( vals, Expr( ___ &amp;gt; 0 ) ); 

//sum of fractional parts
sum( map( vals, Expr( Mod( ___, 1 ) ) ) );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Nov 2017 20:56:18 GMT</pubDate>
    <dc:creator>ih</dc:creator>
    <dc:date>2017-11-09T20:56:18Z</dc:date>
    <item>
      <title>Functional Programming with JSL, Anyone?</title>
      <link>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/46994#M26782</link>
      <description>&lt;P&gt;Does anyone write&amp;nbsp;JSL using functional programming, and if so do you have a standard set of functions that you use?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As an example, the&amp;nbsp;simplified map function below does all of the work of a for loop so you only need to specify an expression and a list and the function returns a list with the function evaluted for each element. In R, a similar function and variants of it can be found in the package &lt;A href="https://cran.r-project.org/web/packages/purrr/purrr.pdf" target="_self"&gt;'purrr'&lt;/A&gt; by Lionel Henry&amp;nbsp;and Hadley Wickham.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// A function to evaluate an expression for each item in a list
// 
// x__   A list
// fn__  An expression containing ___ (three underscores) that
//       is replaced with each element of x__
//
// Returns a list the same length as x__.
//
map = function( {x__, fn__},
	r__ = {};
	for(i__ = 1, i__ &amp;lt;= N items( x__ ), i__++,
		r__ = Insert( r__, Eval( substitute(Name Expr( fn__ ), Expr(___), Expr( x__[i__] ) ) ) );
	);
	return(r__);
);

//Data to evaluate
vals = { 1, 2, 3, -3, -2, 0.5, -1.1, 5.3, 2.7, 0 };

//number of entries above zero
map( vals, Expr( ___ &amp;gt; 0 ) ); 

//sum of fractional parts
sum( map( vals, Expr( Mod( ___, 1 ) ) ) );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 20:56:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/46994#M26782</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2017-11-09T20:56:18Z</dc:date>
    </item>
    <item>
      <title>Re: Functional Programming with JSL, Anyone?</title>
      <link>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/47749#M27195</link>
      <description>I have used this approach, and have functions for generating dynamic journals from a data table, converting a table to nested lists and back again and generating UI dialogue windows.&lt;BR /&gt;&lt;BR /&gt;I've also used JSL to write complex if functions I use a lot (list the conditions,state changes on true and state changes when no longer true (optional)), as I was getting sick of debugging my typos.</description>
      <pubDate>Tue, 28 Nov 2017 08:37:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/47749#M27195</guid>
      <dc:creator>stephen_pearson</dc:creator>
      <dc:date>2017-11-28T08:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: Functional Programming with JSL, Anyone?</title>
      <link>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/47761#M27204</link>
      <description>&lt;P&gt;How do you pass the code to be evaluated to your stored if function?&amp;nbsp; Today I use both expressions or functions but I plan to standardize on one set going forward.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An example map function that evalutes another function:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;map = function( {x, fn},
	r = {};
	for(i = 1, i &amp;lt;= N items( x ), i++,
		r = Insert( r, fn( x[i] ) );
	);
	return(r);
);

//Anonymous function
map({1, 2, 3}, function({n}, n/2));

//Named function
foo = function( {v}, v * 2 );
map({1, 2, 3}, Expr( foo ) );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Nov 2017 13:43:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/47761#M27204</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2017-11-28T13:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: Functional Programming with JSL, Anyone?</title>
      <link>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/47762#M27205</link>
      <description>The stored if function is a bit of a cheat which is why I listed it second. The function parses the list to generate the if statement and then writes that JSL to a file which is then included in the program.&lt;BR /&gt;&lt;BR /&gt;I tried a function creating the if statements on the fly but the performance hit was massive and I realised the code was pretty static, so was easier to store the generated if function and then use it.</description>
      <pubDate>Tue, 28 Nov 2017 13:57:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/47762#M27205</guid>
      <dc:creator>stephen_pearson</dc:creator>
      <dc:date>2017-11-28T13:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: Functional Programming with JSL, Anyone?</title>
      <link>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/47804#M27227</link>
      <description>&lt;P&gt;Funny you asked, I have implemented something just like that a few months ago and thought at the time it might be useful to others. I just published it here:&amp;nbsp;&lt;A href="https://community.jmp.com/t5/JMP-Scripts/MFR-a-Functional-Programming-Library-for-JSL/ta-p/47803" target="_blank"&gt;https://community.jmp.com/t5/JMP-Scripts/MFR-a-Functional-Programming-Library-for-JSL/ta-p/47803&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I hope you find it useful.&lt;/P&gt;
&lt;P&gt;BTW I prefer to use anonymous functions over expressions though I had to switch between them depending on the problem I was trying to solve.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2017 21:10:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/47804#M27227</guid>
      <dc:creator>nascif_jmp</dc:creator>
      <dc:date>2017-11-28T21:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: Functional Programming with JSL, Anyone?</title>
      <link>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/47922#M27277</link>
      <description>&lt;P&gt;I need to spend some time with your library as these function work a little different than I am used to but this is great and thank you for sharing!&amp;nbsp; No doubt you just saved me a bunch of time!&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 04:37:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/47922#M27277</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2017-11-30T04:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: Functional Programming with JSL, Anyone?</title>
      <link>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/637294#M83502</link>
      <description>&lt;P&gt;In the meantime, is there a &lt;STRONG&gt;map&lt;/STRONG&gt; function now directly available in Jmp?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sooo useful!&lt;BR /&gt;&lt;A href="https://reference.wolfram.com/language/ref/Map.html" target="_blank"&gt;https://reference.wolfram.com/language/ref/Map.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 May 2023 08:25:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/637294#M83502</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2023-05-31T08:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: Functional Programming with JSL, Anyone?</title>
      <link>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/637333#M83505</link>
      <description>&lt;P&gt;In JMP 16 three functions were introduced that facilitate this with native functions. They feel different than other languages but are just as 'functional' (laughing at my own pun):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For Each()	     //Do something for each member - similar to apply
Transform Each() //Calculate something for each member - similar to map
Filter Each()    //Return members for which a condition is true - similar to filter&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Find more info about these functions in this help file:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.jmp.com/support/help/en/17.1/index.shtml#page/jmp/conditional-and-logical-functions.shtml#ww10169888" target="_blank"&gt;https://www.jmp.com/support/help/en/17.1/index.shtml#page/jmp/conditional-and-logical-functions.shtml#ww10169888&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 May 2023 12:18:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/637333#M83505</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2023-05-31T12:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: Functional Programming with JSL, Anyone?</title>
      <link>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/637354#M83507</link>
      <description>&lt;P&gt;Many thanks :)&lt;/img&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;Transform Each.&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;BR /&gt;... similar to Table[] in Mathematica:&lt;BR /&gt;&lt;A href="https://reference.wolfram.com/language/ref/Table.html" target="_blank"&gt;https://reference.wolfram.com/language/ref/Table.html&lt;/A&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 01 Jun 2023 21:26:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Functional-Programming-with-JSL-Anyone/m-p/637354#M83507</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2023-06-01T21:26:34Z</dc:date>
    </item>
  </channel>
</rss>

