<?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: how to save expressions in a variable without evaluating? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/how-to-save-expressions-in-a-variable-without-evaluating/m-p/789644#M97003</link>
    <description>&lt;P&gt;Thank you for your reply and the link, Jarmo, they are also very helpful.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Aug 2024 12:58:07 GMT</pubDate>
    <dc:creator>ThomasB</dc:creator>
    <dc:date>2024-08-29T12:58:07Z</dc:date>
    <item>
      <title>how to save expressions in a variable without evaluating?</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-save-expressions-in-a-variable-without-evaluating/m-p/786162#M96913</link>
      <description>&lt;P&gt;While working on a big script, I noticed some interesting behavior regarding expressions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider the following piece of jsl code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;&lt;FONT color="#339966"&gt;// Create a namespace for cleanliness&lt;/FONT&gt;
ns = New Namespace("ns");

&lt;FONT color="#339966"&gt;// Make an example data table dt&lt;/FONT&gt;
ns:dt = &lt;FONT color="#3366FF"&gt;New Table&lt;/FONT&gt;("window", 
				&lt;FONT color="#3366FF"&gt;New Column&lt;/FONT&gt;("a", set values([1,2,3])),
				&lt;FONT color="#3366FF"&gt;New Column&lt;/FONT&gt;("b", set values([1,4,9]))
);

&lt;FONT color="#339966"&gt;// 1. Make an expression gr_exp1 containing the graph builder instructions&lt;/FONT&gt;
ns:gr_exp1 = &lt;FONT color="#3366FF"&gt;expr&lt;/FONT&gt;(ns:gr = ns:dt &amp;lt;&amp;lt; &lt;FONT color="#0000FF"&gt;Graph Builder&lt;/FONT&gt;(
						Show Control Panel( 0 ),
						Variables( X( :a ), Y( :p&lt;/img&gt; ) ),
						Elements( Points( X, Y, Legend( 8 ) ), Smoother( X, Y, Legend( 9 ) ) ));
				);&lt;BR /&gt;&lt;FONT color="#339966"&gt;// Running the expression will build the graph (as expected)
&lt;FONT color="#000000"&gt;ns:gr_exp1;&lt;/FONT&gt;&lt;BR /&gt;				
// 2. Make a function f1 that saves the graph builder instructions into an expression gr_exp2&lt;/FONT&gt;
ns:f1 = &lt;FONT color="#3366FF"&gt;function&lt;/FONT&gt;({},{Default Local},
	ns:gr_exp2 = &lt;FONT color="#3366FF"&gt;expr&lt;/FONT&gt;(ns:gr = ns:dt &amp;lt;&amp;lt; &lt;FONT color="#0000FF"&gt;Graph Builder&lt;/FONT&gt;(
						Show Control Panel( 0 ),
						Variables( X( :a ), Y( :p&lt;/img&gt; ) ),
						Elements( Points( X, Y, Legend( 8 ) ), Smoother( X, Y, Legend( 9 ) ) ));
	);
);
&lt;FONT color="#339966"&gt;// When one runs the function, the graph will be displayed, though only saving the &lt;BR /&gt;// expression into a variable is desired.&lt;/FONT&gt;
ns:f1;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Since for this script I just wanted to save the graph as an expression (and evaluate later), I did not want it to pop-up. After some trial and error, I noticed that nesting the expression in another expression solved the problem:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;ns:f2 = &lt;FONT color="#3366FF"&gt;function&lt;/FONT&gt;({},{Default Local},
	ns:gr_exp2 = &lt;FONT color="#3366FF"&gt;expr&lt;/FONT&gt;(&lt;FONT color="#3366FF"&gt;expr&lt;/FONT&gt;(ns:gr = ns:dt &amp;lt;&amp;lt; Graph Builder(
						Show Control Panel( 0 ),
						Variables( X( :a ), Y( :p&lt;/img&gt; ) ),
						Elements( Points( X, Y, Legend( 8 ) ), Smoother( X, Y, Legend( 9 ) ) ));
	));
);&lt;BR /&gt;&lt;FONT color="#339966"&gt;// Now no graph is displayed when running the function, and the expression is saved!&lt;/FONT&gt;&lt;BR /&gt;ns:f2;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;That solved my issue. But, given the structure of my script, I actually needed to call the function f2 from another function, say f3:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;&lt;FONT color="#339966"&gt;// 4. Now make a function f3 that calls f2 (with the idea of simply saving an expression)&lt;/FONT&gt;
ns:f3 = &lt;FONT color="#3366FF"&gt;function&lt;/FONT&gt;({},{Default Local},
	ns:f2;
);

&lt;FONT color="#339966"&gt;// Running the script will produce a graph again...&lt;/FONT&gt;
ns:f3;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then I noticed that modifying the function f2 to have a triple nested expression solved the issue - it saves the graph as an expression, while suppressing its evaluation:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;&lt;FONT color="#339966"&gt;// This can be solved by modifying f2&lt;/FONT&gt; 
ns:f2 = &lt;FONT color="#3366FF"&gt;function&lt;/FONT&gt;({},{Default Local},
	ns:gr_exp2 = &lt;FONT color="#3366FF"&gt;expr&lt;/FONT&gt;(&lt;FONT color="#3366FF"&gt;expr&lt;/FONT&gt;(&lt;FONT color="#3366FF"&gt;expr&lt;/FONT&gt;(ns:gr = ns:dt &amp;lt;&amp;lt; Graph Builder(
						Show Control Panel( 0 ),
						Variables( X( :a ), Y( :p&lt;/img&gt; ) ),
						Elements( Points( X, Y, Legend( 8 ) ), Smoother( X, Y, Legend( 9 ) ) ));
	)));
);

&lt;FONT color="#339966"&gt;// Running f3 now acts as desired (saves expression and suppresses evaluation of graph)&lt;/FONT&gt;
ns:f3;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;While I have managed to navigate through this issue, my question is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I (correctly) make a function that, upon calling it, saves the expression into a variable &lt;STRONG&gt;without&amp;nbsp;&lt;/STRONG&gt;evaluating the expression?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using JMP Pro 18.0. Any help or comments are appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2024 17:39:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-save-expressions-in-a-variable-without-evaluating/m-p/786162#M96913</guid>
      <dc:creator>ThomasB</dc:creator>
      <dc:date>2024-08-27T17:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to save expressions in a variable without evaluating?</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-save-expressions-in-a-variable-without-evaluating/m-p/786229#M96916</link>
      <description>&lt;P&gt;&lt;A href="https://www.jmp.com/support/help/en/18.0/#page/jmp/expression-functions.shtml?os=win&amp;amp;source=application#ww4993368" target="_blank" rel="noopener"&gt;Name Expr()&lt;/A&gt; might be one of the options you are looking for&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1724782668368.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/67579i3595B743686DF801/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1724782668368.png" alt="jthi_0-1724782668368.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.jmp.com/support/help/en/18.0/#page/jmp/advanced-expressions-macros-and-lists.shtml#ww339382" target="_blank"&gt;https://www.jmp.com/support/help/en/18.0/#page/jmp/advanced-expressions-macros-and-lists.shtml#ww339382&lt;/A&gt;&amp;nbsp; might be a good read. Also &lt;LI-MESSAGE title="Expression Handling Functions: Part I - Unraveling the Expr(), NameExpr(), Eval(), ... Conundrum" uid="28963" url="https://community.jmp.com/t5/JMPer-Cable/Expression-Handling-Functions-Part-I-Unraveling-the-Expr/m-p/28963#U28963" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;(there is no part2 to my knowledge)&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2024 18:22:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-save-expressions-in-a-variable-without-evaluating/m-p/786229#M96916</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-08-27T18:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to save expressions in a variable without evaluating?</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-save-expressions-in-a-variable-without-evaluating/m-p/788120#M96956</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/38150"&gt;@ThomasB&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;please note that the last expression of a function is used as the return value.&lt;BR /&gt;If you just want to assign the expression without "returning" it, please add a dummy return value:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;ns:f1 = function({},{Default Local},
	ns:gr_exp2 = expr(ns:gr = ns:dt &amp;lt;&amp;lt; Graph Builder(
						Show Control Panel( 0 ),
						Variables( X( :a ), Y(  ) ),
						Elements( Points( X, Y, Legend( 8 ) ), Smoother( X, Y, Legend( 9 ) ) ));
	);
	1;
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;ns:f1 = function({},{Default Local},
	ns:gr_exp2 = expr(ns:gr = ns:dt &amp;lt;&amp;lt; Graph Builder(
						Show Control Panel( 0 ),
						Variables( X( :a ), Y(  ) ),
						Elements( Points( X, Y, Legend( 8 ) ), Smoother( X, Y, Legend( 9 ) ) ));
	);
	return(1);
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 12:28:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-save-expressions-in-a-variable-without-evaluating/m-p/788120#M96956</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2024-08-29T12:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to save expressions in a variable without evaluating?</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-save-expressions-in-a-variable-without-evaluating/m-p/789644#M97003</link>
      <description>&lt;P&gt;Thank you for your reply and the link, Jarmo, they are also very helpful.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 12:58:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-save-expressions-in-a-variable-without-evaluating/m-p/789644#M97003</guid>
      <dc:creator>ThomasB</dc:creator>
      <dc:date>2024-08-29T12:58:07Z</dc:date>
    </item>
  </channel>
</rss>

