<?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 How to manipulate JSL function arguments in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-manipulate-JSL-function-arguments/m-p/973172#M110594</link>
    <description>&lt;DIV id="fieldset_0" class="lia-form-fieldset-wrapper lia-form-post-fieldset-toggle"&gt;&lt;FIELDSET class="lia-form-fieldset"&gt;
&lt;DIV id="messageEditor_0" class="MessageEditor"&gt;
&lt;DIV class="lia-js-block-events"&gt;
&lt;DIV class="lia-form-row lia-form-body-entry"&gt;
&lt;DIV class="lia-quilt-row lia-quilt-row-standard"&gt;
&lt;DIV class="lia-quilt-column lia-quilt-column-24 lia-quilt-column-single"&gt;
&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-single"&gt;
&lt;DIV class="lia-form-input-wrapper"&gt;
&lt;DIV id="preview" class="message-preview" role="tabpanel"&gt;
&lt;DIV id="messageView_4ad7bae2ecb631_8506" class="lia-panel-message message-uid-0 lia-component-forums-widget-message-view" data-lia-message-uid="-1"&gt;
&lt;DIV id="messageView2_1_4ad7bae2ecb631_8506" class="lia-message-view-wrapper lia-component-forums-widget-message-view-two" data-lia-message-uid="-1"&gt;
&lt;DIV class="MessageView lia-message-view-forum-message lia-message-view-display lia-row-standard-read lia-thread-topic lia-message-authored-by-you"&gt;
&lt;DIV class="lia-quilt lia-quilt-forum-message lia-quilt-layout-jmp-forum-message3"&gt;
&lt;DIV class="lia-quilt-row lia-quilt-row-main"&gt;
&lt;DIV class="lia-quilt-column lia-quilt-column-24 lia-quilt-column-single lia-quilt-column-main"&gt;
&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-single"&gt;
&lt;DIV class="forum-topic-flex-article"&gt;
&lt;DIV class="forum-article"&gt;
&lt;DIV class="forum-post"&gt;
&lt;DIV id="bodyDisplay_4ad7bae34c09d6_8506" class="lia-message-body lia-component-message-view-widget-body lia-component-body-signature-highlight-escalation lia-component-message-view-widget-body-signature-highlight-escalation"&gt;
&lt;DIV class="lia-message-body-content"&gt;
&lt;P&gt;I'm leaving this here if it helps someone. Maybe I'm inventing hot water, but I couldn't find anything similar.&lt;/P&gt;
&lt;P&gt;Problem: in general it is not possible to directly access the parts of a function "expression" directly, expression in quotes because it's not really an Expression data type but a Function, thus the usual expression manipulation functions do not work:&lt;/P&gt;
&lt;LI-CODE lang="jsl"&gt;f = Function( { x }, Return( x ) );

Show( Type( Name Expr(f) ), N Arg( Name Expr(f) ) );

// output:
Type(Name Expr(f)) = "Function";
N Arg(Name Expr(f)) = 0;&lt;/LI-CODE&gt;
&lt;P&gt;However, there's a trick - you can transform a function to an Expression data&amp;nbsp; type using:&lt;/P&gt;
&lt;LI-CODE lang="jsl"&gt;Parse( Char( Name Expr( function ) ) )&lt;/LI-CODE&gt;
&lt;P&gt;Maybe there's a more elegant way but after hours of research and my own testing I could not find it, and even this method I found pretty much by coincidence just before giving up.&lt;/P&gt;
&lt;P&gt;Anyway, then you can access its arguments using Arg(). It has 2 or 3, depending on presence of locals list. First expression argument is the function inputs list, the second one is locals list if present, the last one is function body.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;f = Function( { greeting, planet }, { output },
	output = Concat( greeting, " ", planet, "!");
	Return( output )
);

f_as_expr = Parse( Char( Name Expr( f ) ) );

Show( Arg( f_as_expr, 1 ), Arg( f_as_expr, 2 ), Arg( f_as_expr, 3 ) )

// output:
Arg(f_as_expr, 1) = {greeting, planet};
Arg(f_as_expr, 2) = {output};
Arg(f_as_expr, 3) = output = greeting || " " || planet || "!"; Return(output);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For example, I have a user interface function&amp;nbsp; with lots of display boxes and most of them are assigned to a variable. I update it quite often so after a while maintaining the locals list becomes painful since I don't want to use {default local} because of less control over variable scope and possible leakage. I know I could use Associative array or similar approach, but since I also maintain the list of display box names in an external list for other purposes, I can dynamically inject it into the function as locals. Of course, you can also modify the function inputs and body in a similar way.&lt;/P&gt;
&lt;LI-CODE lang="jsl"&gt;Names Default To Here(1);

// f must be passed as Name Expr(f), add_locals as list of strings
inject_locals = Function( { f, add_locals }, { f_as_expr, cur_locals, new_locals },
	f_as_expr = Parse( Char( Name Expr( f ) ) );
	add_locals = Transform Each( {al}, add_locals, Parse(al) );
	Match( N Arg( f_as_expr ),
		2,
		Insert Into( f_as_expr, add_locals, 2 ),
		3,
		cur_locals = Arg( f_as_expr, 2);
		new_locals = cur_locals || add_locals;
		Substitute Into( f_as_expr, cur_locals, new_locals ),
		Throw( "inject_local error: unexpected function structure.")
	);
	Return( Eval( Name Expr( f_as_expr ) ) )
);

// simplified example of use
f = Function( {}, { output },
	greeting = "Hello";
	planet = "Earth";
	output = Concat( greeting, " ", planet, "!" )
);

// globals to show that f internals remain local after injection
greeting = "Goodbye";
planet = "Mars";

additional_locals = { "greeting", "planet" };

f_injected = inject_locals( Name Expr(f), additional_locals );

Show( f, f_injected, f_injected(), greeting, planet )

// output:
f = Function({},{output},greeting = "Hello"; planet = "Earth"; output = greeting || " " || planet || "!");

f_injected = Function({},{output, greeting, planet},greeting = "Hello"; planet = "Earth"; output = greeting || " " || planet || "!");

f_injected() = "Hello Earth!";
greeting = "Goodbye";
planet = "Mars";&lt;/LI-CODE&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="lia-quilt-row lia-quilt-row-footer"&gt;
&lt;DIV class="lia-quilt-column lia-quilt-column-24 lia-quilt-column-single lia-quilt-column-message-footer"&gt;
&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-single"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/FIELDSET&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 24 Sep 2026 09:54:49 GMT</pubDate>
    <dc:creator>AlterEgo</dc:creator>
    <dc:date>2026-09-24T09:54:49Z</dc:date>
    <item>
      <title>How to manipulate JSL function arguments</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-manipulate-JSL-function-arguments/m-p/973172#M110594</link>
      <description>&lt;DIV id="fieldset_0" class="lia-form-fieldset-wrapper lia-form-post-fieldset-toggle"&gt;&lt;FIELDSET class="lia-form-fieldset"&gt;
&lt;DIV id="messageEditor_0" class="MessageEditor"&gt;
&lt;DIV class="lia-js-block-events"&gt;
&lt;DIV class="lia-form-row lia-form-body-entry"&gt;
&lt;DIV class="lia-quilt-row lia-quilt-row-standard"&gt;
&lt;DIV class="lia-quilt-column lia-quilt-column-24 lia-quilt-column-single"&gt;
&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-single"&gt;
&lt;DIV class="lia-form-input-wrapper"&gt;
&lt;DIV id="preview" class="message-preview" role="tabpanel"&gt;
&lt;DIV id="messageView_4ad7bae2ecb631_8506" class="lia-panel-message message-uid-0 lia-component-forums-widget-message-view" data-lia-message-uid="-1"&gt;
&lt;DIV id="messageView2_1_4ad7bae2ecb631_8506" class="lia-message-view-wrapper lia-component-forums-widget-message-view-two" data-lia-message-uid="-1"&gt;
&lt;DIV class="MessageView lia-message-view-forum-message lia-message-view-display lia-row-standard-read lia-thread-topic lia-message-authored-by-you"&gt;
&lt;DIV class="lia-quilt lia-quilt-forum-message lia-quilt-layout-jmp-forum-message3"&gt;
&lt;DIV class="lia-quilt-row lia-quilt-row-main"&gt;
&lt;DIV class="lia-quilt-column lia-quilt-column-24 lia-quilt-column-single lia-quilt-column-main"&gt;
&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-single"&gt;
&lt;DIV class="forum-topic-flex-article"&gt;
&lt;DIV class="forum-article"&gt;
&lt;DIV class="forum-post"&gt;
&lt;DIV id="bodyDisplay_4ad7bae34c09d6_8506" class="lia-message-body lia-component-message-view-widget-body lia-component-body-signature-highlight-escalation lia-component-message-view-widget-body-signature-highlight-escalation"&gt;
&lt;DIV class="lia-message-body-content"&gt;
&lt;P&gt;I'm leaving this here if it helps someone. Maybe I'm inventing hot water, but I couldn't find anything similar.&lt;/P&gt;
&lt;P&gt;Problem: in general it is not possible to directly access the parts of a function "expression" directly, expression in quotes because it's not really an Expression data type but a Function, thus the usual expression manipulation functions do not work:&lt;/P&gt;
&lt;LI-CODE lang="jsl"&gt;f = Function( { x }, Return( x ) );

Show( Type( Name Expr(f) ), N Arg( Name Expr(f) ) );

// output:
Type(Name Expr(f)) = "Function";
N Arg(Name Expr(f)) = 0;&lt;/LI-CODE&gt;
&lt;P&gt;However, there's a trick - you can transform a function to an Expression data&amp;nbsp; type using:&lt;/P&gt;
&lt;LI-CODE lang="jsl"&gt;Parse( Char( Name Expr( function ) ) )&lt;/LI-CODE&gt;
&lt;P&gt;Maybe there's a more elegant way but after hours of research and my own testing I could not find it, and even this method I found pretty much by coincidence just before giving up.&lt;/P&gt;
&lt;P&gt;Anyway, then you can access its arguments using Arg(). It has 2 or 3, depending on presence of locals list. First expression argument is the function inputs list, the second one is locals list if present, the last one is function body.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;f = Function( { greeting, planet }, { output },
	output = Concat( greeting, " ", planet, "!");
	Return( output )
);

f_as_expr = Parse( Char( Name Expr( f ) ) );

Show( Arg( f_as_expr, 1 ), Arg( f_as_expr, 2 ), Arg( f_as_expr, 3 ) )

// output:
Arg(f_as_expr, 1) = {greeting, planet};
Arg(f_as_expr, 2) = {output};
Arg(f_as_expr, 3) = output = greeting || " " || planet || "!"; Return(output);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For example, I have a user interface function&amp;nbsp; with lots of display boxes and most of them are assigned to a variable. I update it quite often so after a while maintaining the locals list becomes painful since I don't want to use {default local} because of less control over variable scope and possible leakage. I know I could use Associative array or similar approach, but since I also maintain the list of display box names in an external list for other purposes, I can dynamically inject it into the function as locals. Of course, you can also modify the function inputs and body in a similar way.&lt;/P&gt;
&lt;LI-CODE lang="jsl"&gt;Names Default To Here(1);

// f must be passed as Name Expr(f), add_locals as list of strings
inject_locals = Function( { f, add_locals }, { f_as_expr, cur_locals, new_locals },
	f_as_expr = Parse( Char( Name Expr( f ) ) );
	add_locals = Transform Each( {al}, add_locals, Parse(al) );
	Match( N Arg( f_as_expr ),
		2,
		Insert Into( f_as_expr, add_locals, 2 ),
		3,
		cur_locals = Arg( f_as_expr, 2);
		new_locals = cur_locals || add_locals;
		Substitute Into( f_as_expr, cur_locals, new_locals ),
		Throw( "inject_local error: unexpected function structure.")
	);
	Return( Eval( Name Expr( f_as_expr ) ) )
);

// simplified example of use
f = Function( {}, { output },
	greeting = "Hello";
	planet = "Earth";
	output = Concat( greeting, " ", planet, "!" )
);

// globals to show that f internals remain local after injection
greeting = "Goodbye";
planet = "Mars";

additional_locals = { "greeting", "planet" };

f_injected = inject_locals( Name Expr(f), additional_locals );

Show( f, f_injected, f_injected(), greeting, planet )

// output:
f = Function({},{output},greeting = "Hello"; planet = "Earth"; output = greeting || " " || planet || "!");

f_injected = Function({},{output, greeting, planet},greeting = "Hello"; planet = "Earth"; output = greeting || " " || planet || "!");

f_injected() = "Hello Earth!";
greeting = "Goodbye";
planet = "Mars";&lt;/LI-CODE&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="lia-quilt-row lia-quilt-row-footer"&gt;
&lt;DIV class="lia-quilt-column lia-quilt-column-24 lia-quilt-column-single lia-quilt-column-message-footer"&gt;
&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-single"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/FIELDSET&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 24 Sep 2026 09:54:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-manipulate-JSL-function-arguments/m-p/973172#M110594</guid>
      <dc:creator>AlterEgo</dc:creator>
      <dc:date>2026-09-24T09:54:49Z</dc:date>
    </item>
  </channel>
</rss>

