<?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: Indexing the return value of a function in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Indexing-the-return-value-of-a-function/m-p/927652#M108530</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;If you need to evaluate an expression "manually" [&lt;U&gt;&lt;STRONG&gt;before&lt;/STRONG&gt; &lt;/U&gt;taking the fist item from the result], use Eval():&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In my opinion that creates code which is difficult to read and should not be used, just return the value and use that. If you know you want just a&amp;nbsp; specific index (&lt;STRONG&gt;and know how many there are&lt;/STRONG&gt;) you can use a list and "throw away" the rest&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

return_list = Function({}, {Default Local}, return({1,2,3}));

{res, _, _} = return_list(); 
show(res, _);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;correctly assigns&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;x=Expr(hello)&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and prints:&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In my opinion that should result in an error (currently it is in my opinion unexpected behavior). My guess is that this works due to how Glue behaves (it returns the last result and it then gets evaluated)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

Eval(
	x = Expr(hello);
	Print(x);
);&lt;BR /&gt;// Eval(Glue(Assign(x, Expr(hello)), Print(x)));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;vs (&lt;EM&gt;Name Unresolved: hello in access or evaluation of 'hello' , hello/*###*/&lt;/EM&gt;)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

Eval(
	x = Expr(hello);
);&lt;BR /&gt;// Eval(Assign(x, Expr(hello)));&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I feel like this is what should always happen if Eval is being used in a case like this (attempt to evaluate Expr() -&amp;gt; fail evaluating it -&amp;gt; throw error).&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/11257"&gt;@EvanMcCorkle&lt;/a&gt;&amp;nbsp;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

a = 1;

Try(
	Eval(
		x = Expr(hello);
		y = Expr(a);
	);
,
	Write("\!NFirst Example: ", exception_msg);
);

Try(
	Eval(
		y = Expr(a);
		x = Expr(hello);
	);
,
	Write("\!Second Example: ", exception_msg);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you wish store just the hello name in variable, use Name Expr()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

x = NameExpr(hello);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.jmp.com/support/help/en/18.2/#page/jmp/advanced-expressions-macros-and-lists.shtml" target="_blank" rel="noopener"&gt;Scripting Guide &amp;gt; Programming Methods &amp;gt; Advanced Expressions, Macros, and Lists&lt;/A&gt;&amp;nbsp;this does have some mistakes but overall it is correct and a good read.&lt;/P&gt;</description>
    <pubDate>Sat, 31 Jan 2026 06:52:09 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2026-01-31T06:52:09Z</dc:date>
    <item>
      <title>Indexing the return value of a function</title>
      <link>https://community.jmp.com/t5/Discussions/Indexing-the-return-value-of-a-function/m-p/926389#M108425</link>
      <description>&lt;P&gt;Today's challenge:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;f=Function({}, {1,2,3});

tmp=f();
y=tmp[1]; // works

x=f()[1] // doesn't&amp;nbsp;work&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;understanding the issue helps a lot to understand how JSL works&amp;nbsp; : - )&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jan 2026 14:16:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Indexing-the-return-value-of-a-function/m-p/926389#M108425</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2026-01-27T14:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing the return value of a function</title>
      <link>https://community.jmp.com/t5/Discussions/Indexing-the-return-value-of-a-function/m-p/926402#M108426</link>
      <description>&lt;P&gt;the inverse problem:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
x=1;
Eval(x=1); // "does the same"

x= Expr(hello);
Eval(x= Expr(hello)); // fails&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Jan 2026 06:37:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Indexing-the-return-value-of-a-function/m-p/926402#M108426</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2026-01-27T06:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing the return value of a function</title>
      <link>https://community.jmp.com/t5/Discussions/Indexing-the-return-value-of-a-function/m-p/926447#M108433</link>
      <description>&lt;P&gt;&lt;LI-MESSAGE title="Does Head evaluate its argument?" uid="729500" url="https://community.jmp.com/t5/Discussions/Does-Head-evaluate-its-argument/m-p/729500#U729500" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;concerning &lt;STRONG&gt;assign&lt;/STRONG&gt;, does it evaluate its arguments?&lt;BR /&gt;1. arg: no&lt;BR /&gt;2. arg: yes&lt;BR /&gt;&lt;BR /&gt;If you need to evaluate an expression "manually" [&lt;U&gt;&lt;STRONG&gt;before&lt;/STRONG&gt; &lt;/U&gt;taking the fist item from the result], use Eval():&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;x=f()[1] // doesn't work
x=Eval(f())[1] // works&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;concerning &lt;STRONG&gt;glue&lt;/STRONG&gt;:&lt;BR /&gt;any args: yes&lt;/P&gt;
&lt;P&gt;.... and Eval:&lt;BR /&gt;yes, of course!&lt;BR /&gt;&lt;BR /&gt;besides that, there is an additional &lt;STRONG&gt;evaluation of the return value&lt;/STRONG&gt;&amp;nbsp;*) - after a first evaluation of the argument. So&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Eval(print(1);x= Expr(hello);print(x); Expr(print(2)));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;correctly assigns &lt;FONT face="courier new,courier"&gt;x=Expr(hello)&lt;/FONT&gt; and prints:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1769516471823.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/92293i6BF9E3D0AA0E473F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_0-1769516471823.png" alt="hogi_0-1769516471823.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;*) -&amp;gt; link / documentation / community?&lt;/P&gt;</description>
      <pubDate>Sat, 31 Jan 2026 08:43:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Indexing-the-return-value-of-a-function/m-p/926447#M108433</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2026-01-31T08:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing the return value of a function</title>
      <link>https://community.jmp.com/t5/Discussions/Indexing-the-return-value-of-a-function/m-p/927652#M108530</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;If you need to evaluate an expression "manually" [&lt;U&gt;&lt;STRONG&gt;before&lt;/STRONG&gt; &lt;/U&gt;taking the fist item from the result], use Eval():&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In my opinion that creates code which is difficult to read and should not be used, just return the value and use that. If you know you want just a&amp;nbsp; specific index (&lt;STRONG&gt;and know how many there are&lt;/STRONG&gt;) you can use a list and "throw away" the rest&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

return_list = Function({}, {Default Local}, return({1,2,3}));

{res, _, _} = return_list(); 
show(res, _);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;correctly assigns&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;x=Expr(hello)&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and prints:&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In my opinion that should result in an error (currently it is in my opinion unexpected behavior). My guess is that this works due to how Glue behaves (it returns the last result and it then gets evaluated)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

Eval(
	x = Expr(hello);
	Print(x);
);&lt;BR /&gt;// Eval(Glue(Assign(x, Expr(hello)), Print(x)));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;vs (&lt;EM&gt;Name Unresolved: hello in access or evaluation of 'hello' , hello/*###*/&lt;/EM&gt;)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

Eval(
	x = Expr(hello);
);&lt;BR /&gt;// Eval(Assign(x, Expr(hello)));&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I feel like this is what should always happen if Eval is being used in a case like this (attempt to evaluate Expr() -&amp;gt; fail evaluating it -&amp;gt; throw error).&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/11257"&gt;@EvanMcCorkle&lt;/a&gt;&amp;nbsp;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

a = 1;

Try(
	Eval(
		x = Expr(hello);
		y = Expr(a);
	);
,
	Write("\!NFirst Example: ", exception_msg);
);

Try(
	Eval(
		y = Expr(a);
		x = Expr(hello);
	);
,
	Write("\!Second Example: ", exception_msg);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you wish store just the hello name in variable, use Name Expr()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

x = NameExpr(hello);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.jmp.com/support/help/en/18.2/#page/jmp/advanced-expressions-macros-and-lists.shtml" target="_blank" rel="noopener"&gt;Scripting Guide &amp;gt; Programming Methods &amp;gt; Advanced Expressions, Macros, and Lists&lt;/A&gt;&amp;nbsp;this does have some mistakes but overall it is correct and a good read.&lt;/P&gt;</description>
      <pubDate>Sat, 31 Jan 2026 06:52:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Indexing-the-return-value-of-a-function/m-p/927652#M108530</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2026-01-31T06:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing the return value of a function</title>
      <link>https://community.jmp.com/t5/Discussions/Indexing-the-return-value-of-a-function/m-p/927660#M108532</link>
      <description>&lt;P&gt;Thanks for the additional examples and your thoughts.&lt;/P&gt;</description>
      <pubDate>Sat, 31 Jan 2026 08:58:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Indexing-the-return-value-of-a-function/m-p/927660#M108532</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2026-01-31T08:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing the return value of a function</title>
      <link>https://community.jmp.com/t5/Discussions/Indexing-the-return-value-of-a-function/m-p/927773#M108540</link>
      <description>&lt;P&gt;Ah, things get much clearer when we take a&amp;nbsp;&lt;SPAN&gt;function &lt;EM&gt;&lt;STRONG&gt;which is defined with arguments&lt;/STRONG&gt;&lt;/EM&gt;:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;g=Function({x}, {1,2,3});
x=g()[1] //  doesn't work  (uses the function itself and takes the first element)

x=g("")[1] // works&amp;nbsp;-&amp;gt;&amp;nbsp;1   (runs the function - then takes the first element)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;If there is a function&amp;nbsp;&lt;U&gt;with empty brackets:&lt;/U&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;take&lt;/STRONG&gt; &lt;SPAN&gt;the function itself -&amp;nbsp; &lt;/SPAN&gt;&lt;U style="font-size: 1em;"&gt;&lt;STRONG&gt;don't&lt;/STRONG&gt; &lt;/U&gt;&lt;SPAN&gt;evaluate it&lt;/SPAN&gt;&lt;FONT face="courier new,courier" style="font-size: 1em;"&gt;.&lt;/FONT&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;If the function shows up with &lt;U&gt;argument(s) inside the brackets:&lt;/U&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;run&lt;/STRONG&gt; the function! then take the first element of the result&lt;/EM&gt;&lt;EM&gt;&lt;FONT face="courier new,courier" style="font-size: 1em;"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/EM&gt;&lt;FONT style="font-size: 1em;"&gt;especially if the function is send()&lt;/FONT&gt;&lt;EM&gt;&lt;EM&gt;&lt;FONT style="font-size: 1em;"&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/EM&gt;&lt;/EM&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;img = new image(Open( "$SAMPLE_IMAGES/tile.jpg", jpg ));
x = (img &amp;lt;&amp;lt; get size)[1];  // works
x = send(img, getsize)[1]&amp;nbsp;;&amp;nbsp;//&amp;nbsp;same&amp;nbsp;as&amp;nbsp;this&amp;nbsp;one&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Sun, 01 Feb 2026 08:57:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Indexing-the-return-value-of-a-function/m-p/927773#M108540</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2026-02-01T08:57:46Z</dc:date>
    </item>
  </channel>
</rss>

