<?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: Values logged in Print not matching values in script executions in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Values-logged-in-Print-not-matching-values-in-script-executions/m-p/625120#M82393</link>
    <description>&lt;P&gt;boxes have their own scope. currently you're doing a modal window but imagine if you weren't and the function closed and all the local variables are now gone.&amp;nbsp; For stuff like that I usually do something like.&amp;nbsp;&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);
test = function({something_passed, kwargs={}},
    {DEFAULT LOCAL},
    // Kwargs
    kwarg = Try(kwargs["kwarg"], "default"); // kwarg description
    something_not_passed = 14;
	
    nw = new window("Scope",
		window:something_not_passed = something_not_passed; // just assignthe variable to the display
		window:something_passed = something_passed; 
		window:something_direct = 42;

		buttonbox("OK", 
			&amp;lt;&amp;lt;Set Function(
				Function({self}, {DEFAULT LOCAL},
					show(window:something_not_passed, window:something_passed, window:something_direct);
				)
			)
		)
    );

    return(nw);

);
nw = test(28);
//your variables are gone now, but when you click okay they're still in the box&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 22 Apr 2023 02:55:17 GMT</pubDate>
    <dc:creator>vince_faller</dc:creator>
    <dc:date>2023-04-22T02:55:17Z</dc:date>
    <item>
      <title>Values logged in Print not matching values in script executions</title>
      <link>https://community.jmp.com/t5/Discussions/Values-logged-in-Print-not-matching-values-in-script-executions/m-p/623179#M82208</link>
      <description>&lt;P&gt;Hi, I am trying to understand some behavior in a function that uses Default Local scope. Namely, the values that appear in my logs when using Print statements do not match the values that my code is executed with. For example in this script:&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 );

EXAMPLE_VALUE = "100";

showExampleModal = Function( {},
	{Default Local},
	
	Print("Here:EXAMPLE_VALUE: " || Char(Here:EXAMPLE_VALUE));
	Print("EXAMPLE_VALUE: " || Char(EXAMPLE_VALUE));

	modal = New Window( "Example Modal",
		&amp;lt;&amp;lt;Modal,
		Border Box( Left( 2 ), Right( 2 ),
			V List Box(
				H Center Box( Text Box( "Here:EXAMPLE_VALUE: " || Char(Here:EXAMPLE_VALUE) ) ),
				H Center Box( Text Box( "EXAMPLE_VALUE: " || Char(EXAMPLE_VALUE) ) ),
			), 

		),
	);
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In my logs I see:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;"Here:EXAMPLE_VALUE: 100"
"EXAMPLE_VALUE: 100"&lt;/PRE&gt;&lt;P&gt;However in my modal I see:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Here:EXAMPLE_VALUE: 100
EXAMPLE_VALUE: .&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:08:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Values-logged-in-Print-not-matching-values-in-script-executions/m-p/623179#M82208</guid>
      <dc:creator>mat-ski</dc:creator>
      <dc:date>2023-06-09T16:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: Values logged in Print not matching values in script executions</title>
      <link>https://community.jmp.com/t5/Discussions/Values-logged-in-Print-not-matching-values-in-script-executions/m-p/624949#M82379</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/47422"&gt;@mat-ski&lt;/a&gt;, when declaring the Default Local namespace in a function, all unscoped variables are local to that function (see &lt;A href="https://www.jmp.com/support/help/en/17.1/#page/jmp/programming-functions.shtml?&amp;amp;source=application#ww5013741" target="_blank" rel="noopener"&gt;here&lt;/A&gt;). EXAMPLE_VALUE is declared outside the function, so the modal displays the correct value only when the variable reference is scoped to Here. Declaring EXAMPLE_VALUE inside the function will make it local and available to the function, but it then wouldn't exist in the Here namespace to be accessible to the rest of the script. Here's a &lt;A href="https://www.jmp.com/support/help/en/17.1/#page/jmp/reference-namespaces-and-scopes.shtml#" target="_blank" rel="noopener"&gt;helpful page on namespace referencing&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 19:08:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Values-logged-in-Print-not-matching-values-in-script-executions/m-p/624949#M82379</guid>
      <dc:creator>Ross_Metusalem</dc:creator>
      <dc:date>2023-04-21T19:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: Values logged in Print not matching values in script executions</title>
      <link>https://community.jmp.com/t5/Discussions/Values-logged-in-Print-not-matching-values-in-script-executions/m-p/625006#M82384</link>
      <description>&lt;P&gt;According to the documentation that you linked on namespace referencing it states that for user defined functions with Default Local "&lt;SPAN&gt;reference rule is unchanged" and the reference rule for unqualified references states:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;If the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;Names Default To Here&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;mode is on, JMP looks for the variable in these locations:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN class=""&gt;Local&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;namespace&lt;/LI&gt;&lt;LI&gt;Here&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;namespace&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;current data table&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So it seems like the documentation is stating that it should still fallback to Here in case there is no local variable with the name in question in the Local namespace.&lt;BR /&gt;&lt;BR /&gt;Separately, it seems problematic to me that the behavior of the Print statement does not match the behavior of the context from which the Print is being made.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 20:03:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Values-logged-in-Print-not-matching-values-in-script-executions/m-p/625006#M82384</guid>
      <dc:creator>mat-ski</dc:creator>
      <dc:date>2023-04-21T20:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: Values logged in Print not matching values in script executions</title>
      <link>https://community.jmp.com/t5/Discussions/Values-logged-in-Print-not-matching-values-in-script-executions/m-p/625011#M82387</link>
      <description>&lt;P&gt;When dealing with scopes in JSL. I pretty much always say just be explicit if you're moving about between them.&amp;nbsp; I've spent DAYS trying to debug a single scoping issue.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 20:12:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Values-logged-in-Print-not-matching-values-in-script-executions/m-p/625011#M82387</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2023-04-21T20:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: Values logged in Print not matching values in script executions</title>
      <link>https://community.jmp.com/t5/Discussions/Values-logged-in-Print-not-matching-values-in-script-executions/m-p/625060#M82389</link>
      <description>&lt;P&gt;Based on some further debugging I believe that I understand what is happening.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Updated code:&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 );

EXAMPLE_VALUE = "100";

showExampleModal = Function( {},
	{Default Local}, 

	// (1)
	hereStr = "Here:EXAMPLE_VALUE: " || Char( Here:EXAMPLE_VALUE );
	unqualifiedStr = "EXAMPLE_VALUE: " || Char( EXAMPLE_VALUE );

  // (2)
	hereStrTextBox = Text Box( "Here:EXAMPLE_VALUE: " || Char( Here:EXAMPLE_VALUE ) );
	unqualifiedStrTextBox = Text Box( "EXAMPLE_VALUE: " || Char( EXAMPLE_VALUE ) );
	
  // (3)
	Print( hereStr );
	Print( unqualifiedStr );

	modal = New Window( "Example Modal",
		&amp;lt;&amp;lt;Modal,
		Border Box( Left( 2 ), Right( 2 ),
			V List Box(
        // (4)
				H Center Box( Text Box( hereStr ) ), // Defined
				H Center Box( Text Box( unqualifiedStr ) ), // Defined
				H Center Box( Text Box( "Here:EXAMPLE_VALUE: " || Char( Here:EXAMPLE_VALUE ) ) ), // Defined
				H Center Box( Text Box( "EXAMPLE_VALUE: " || Char( EXAMPLE_VALUE ) ) ), // Not Defined
				H Center Box( hereStrTextBox ), // Defined
				H Center Box( unqualifiedStrTextBox ), // Defined

			), 

		), 

		H List Box(
			Spacer Box(),
			Button Box( "OK", 
        // (5)
				Print( "On Click" );
				Print( "Here:EXAMPLE_VALUE: " || Char( Here:EXAMPLE_VALUE ) ); // Defined
				Print( "EXAMPLE_VALUE: " || Char( EXAMPLE_VALUE ) ); // Not defined
			)
		), 

	);
);&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;At (1) the assigments are evaluated right away and so when they are passed later to the Print/Text Box they are defined as I expect. This is confirmed by the output of (3) and the first to Text Boxes of (4).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At (2) the Text Boxes are again evaluated at the time the line is executed, and so when they are displayed, they are again defined using the values that I expect. This is confirmed by the last two Text Boxes of (4)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The middle two Text Boxes of (4) are not in fact evaluated immediately, but passed to the Center Box (or maybe the List Box?) as expressions, and evaluated later/in another scope (I guess the scope of either the List Box or the Center Box). As a result the value of EXAMPLE_VALUE is not what I expected, instead it is the value of EXAMPLE_VALUE in whatever other scope it is being evaluated in (namely it is undefined).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This seems to be confirmed by (5), which also passes the Prints as expressions to be evaluated later / in another scope.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this accurate?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 21:41:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Values-logged-in-Print-not-matching-values-in-script-executions/m-p/625060#M82389</guid>
      <dc:creator>mat-ski</dc:creator>
      <dc:date>2023-04-21T21:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: Values logged in Print not matching values in script executions</title>
      <link>https://community.jmp.com/t5/Discussions/Values-logged-in-Print-not-matching-values-in-script-executions/m-p/625120#M82393</link>
      <description>&lt;P&gt;boxes have their own scope. currently you're doing a modal window but imagine if you weren't and the function closed and all the local variables are now gone.&amp;nbsp; For stuff like that I usually do something like.&amp;nbsp;&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);
test = function({something_passed, kwargs={}},
    {DEFAULT LOCAL},
    // Kwargs
    kwarg = Try(kwargs["kwarg"], "default"); // kwarg description
    something_not_passed = 14;
	
    nw = new window("Scope",
		window:something_not_passed = something_not_passed; // just assignthe variable to the display
		window:something_passed = something_passed; 
		window:something_direct = 42;

		buttonbox("OK", 
			&amp;lt;&amp;lt;Set Function(
				Function({self}, {DEFAULT LOCAL},
					show(window:something_not_passed, window:something_passed, window:something_direct);
				)
			)
		)
    );

    return(nw);

);
nw = test(28);
//your variables are gone now, but when you click okay they're still in the box&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Apr 2023 02:55:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Values-logged-in-Print-not-matching-values-in-script-executions/m-p/625120#M82393</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2023-04-22T02:55:17Z</dc:date>
    </item>
  </channel>
</rss>

