cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
0 Kudos

Substitute First Occurrence

It would be quite convenient if JMP allowed the Substitute() function to have an optional argument such as Substitute( ...., First Occurrence( 1 ) ).  This will help when passing arguments into a function by reference.  Consider the following:

some function = Function( {_function, _args},
	{Default Local},
	function = Name Expr( _function );
	Eval( Substitute( _args, {}, Expr( function ) ) )
);

other function = Function( {_1, _2, _3 = "optional"},
	Show( _1, _2, _3 )
);

some function( Name Expr( other function ), {1, 2, 3} );
/* OUTPUT
_1 = 1;
_2 = 2;
_3 = 3;
*/

some function( Name Expr( other function ), {1, {2, 4}, 3} );
/* EXPECTED OUTPUT
_1 = 1;
_2 = {2, 4};
_3 = 3;
*/

Here in the first function I am calling a referenced function with a given argument list.  The problem is that the Subsitute() replaces all lists with the function call, instead of the outer one only.  This is where it would be nice to substitute only the first occurrence of the List() expression.

2 Comments
Status changed to: Acknowledged

Hi @ErraticAttack, thank you for your suggestion! We have captured your request and will take it under consideration.

SamGardner
Staff
Status changed to: Investigating

@ErraticAttack thanks for the suggestion.  We are looking into this and will follow up on what we decide to do or if there is a workaround to do what you want to do.