Choose Language Hide Translation Bar
Highlighted
dileepkr
Level III

USER defined functions: Check if the function exists/loaded after Include

Hi Folks,

 

I am trying to figure out a way to check if a user defined function exists before calling it. Is there a way to do this check in JMP?

 

Eg: 

user_func.jsl:

user_func = Function ({},{},

.....

);

 

Main.jsl:

Include("C:\Documents\user_func.jsl")

.

down in the code

.

.

??How to check if user_func exists??

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
txnelson
Super User

Re: USER defined functions: Check if the function exists/loaded after Include

You can use the IsEmpty() function.  See the example below;

Clear Symbols();
Show( Is Empty( user_func ) );
user_func = Function( {}, {} );
Show( Is Empty( user_func ) );
clear symbols();
Jim

View solution in original post

Highlighted
txnelson
Super User

Re: USER defined functions: Check if the function exists/loaded after Include

Here is how I would handle that case

func_name = "user_func";eval(parse("Show( Is Empty( " || func_name || ") ) ;"));
Jim

View solution in original post

5 REPLIES 5
Highlighted
txnelson
Super User

Re: USER defined functions: Check if the function exists/loaded after Include

You can use the IsEmpty() function.  See the example below;

Clear Symbols();
Show( Is Empty( user_func ) );
user_func = Function( {}, {} );
Show( Is Empty( user_func ) );
clear symbols();
Jim

View solution in original post

Highlighted
dileepkr
Level III

Re: USER defined functions: Check if the function exists/loaded after Include

That worked, thank you very much !
Highlighted
dileepkr
Level III

Re: USER defined functions: Check if the function exists/loaded after Include

Hi Jim @txnelson ,

 

In another case, what to do if the function name is stored as a string in a variable?

 

Clear Symbols();
user_func = Function( {}, {} );
func_name = "user_func";

Show( Is Empty( Parse(func_name) ) ); //This doesnt work, any alternatives???
Clear Symbols();

 

Highlighted
txnelson
Super User

Re: USER defined functions: Check if the function exists/loaded after Include

Here is how I would handle that case

func_name = "user_func";eval(parse("Show( Is Empty( " || func_name || ") ) ;"));
Jim

View solution in original post

Highlighted

Re: USER defined functions: Check if the function exists/loaded after Include

Names Default to Here( 1 );

user_func = Function( {}, Print( "I'm Here!" ) );
func_name = "user_func";

Show( Is Empty( Parse( func_name || "()" ) ) ); 
Learn it once, use it forever!
Article Labels

    There are no labels assigned to this post.