cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Neo
Neo
Level VI

Running a script after making a change. Not working without closing and re-opening the script -why?

I am learning JSL and getting a behaviour which I do not think I got when I started. I would like to know if this behaviour is expected or if it is occurring due to a setting change I may have made inadvertently.

I have a simple "main" script which calls a function and another script. When I open JMP fresh and run fresh the main script or the other function/scripts it calls, all of them run fine and produce expected results. However, they do not work when I make a change in any of them (e.g. if I comment the script which is included in the main script, e.g. the last line below). If I close all the open scripts then re-fire them they work again. Coming from other programming languages I do not expect such a behaviour. Any direction is much appreciated

Examples of my mainscript below (I am on JMP13). 

 

getDataTable = getDataTable4partID("partID","partIDname");
include ("plotallcharts.jsl");
include ("generateJournal.jsl");

Commenting the last line above (or if I uncomment clear log ()) i.e.

//clear log ();
getDataTable = getDataTable4partID("partID","partIDname");
include ("plotallcharts.jsl");
//include ("generateJournal.jsl");

gives me the following error in the above script

Name Unresolved: getDataTable4partID in access or evaluation of 'getDataTable4partID' , getDataTable4partID( "partID", "partIDname" ) /*###*/

Closing all open scripts and functions (and sometimes JMP) and firing back them again seems to get everything working again. Not sure what is going on....

Any direction is much appreciated.

 

 

When it's too good to be true, it's neither
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Running a script after making a change. Not working without closing and re-opening the script -why?

Yes, the getDataTable4partID function must be parsed by JSL prior to you being able to call it.  The include statement, reads in the function, and loads it into memory.  Once it is in memory, it can be called.

Jim

View solution in original post

10 REPLIES 10
txnelson
Super User

Re: Running a script after making a change. Not working without closing and re-opening the script -why?

In your example, I do not see where you define the function

 

getDataTable4partID

 JSL is an interpreted language, and requires the creation of any items referenced in the code, prior to the calling of it.  It is not a compiled language, which first passes through all of the code and identifying functions etc.  Now what can be confusion is that once the function is defined, it will remain in memory and available until it is cleared with a

clear symbols();
// or
clear globals();

If you follow through your code with this in mind, you may see why your JSL cannot find the function.

Jim
Neo
Neo
Level VI

Re: Running a script after making a change. Not working without closing and re-opening the script -why?

Thanks @txnelson.

Here is the function 

getDataTable4partID

Are you suggesting that I use 

clear symbols();
// clear globals();

at the top of my main script?

If yes, then I have tired it without any change in behaviour.

Also, I forgot to mention above that when the main script does not run (after making a change in it) and I need to restart JMP to make the script run as expected again, I also need to run the function my main script is calling, once,  without which my main script does not run. This is clearly an undesirable behaviour and I worry that I am not doing things properly. 

When it's too good to be true, it's neither
txnelson
Super User

Re: Running a script after making a change. Not working without closing and re-opening the script -why?

Your should start your whole script with:

Names Default to Here( 1 );
Clear Symbols();

This will stabilize the Namespace environment and clear out all of  the previous values, thus starting you fresh each time you run the code from the top. 

Jim
Neo
Neo
Level VI

Re: Running a script after making a change. Not working without closing and re-opening the script -why?

Thanks @txnelson. OK so this is what I did and now my scripts and functions are not working even after closing and re-running or after restarting JMP.

 

My main script

Names Default to Here( 1 );
Clear Symbols();
getDataTable = getDataTable4partID("partID","partIDname"); 
include ("plotallcharts.jsl"); 
include ("generateJournal.jsl");

My function is (without database details)

Names Default to Here (1)
getDataTable4PartID = Function({PartID}, {dtTemp},
	dtTemp = Open Database("connectionstring",
		"select '" || PartID || "' as value
		from dual",
		PartID
	);
	return(dtTemp);
);

and my script 

plotallcharts.jsl;

also has its fist line as 

Names Default to Here (1)

I am still getting the error

Name Unresolved: getDataTable4partID in access or evaluation of 'getDataTable4partID' , getDataTable4partID( "partID", "partIDname" ) /*###*/

but sometimes the log is not showing anything upon running the main script. 

 

When it's too good to be true, it's neither
txnelson
Super User

Re: Running a script after making a change. Not working without closing and re-opening the script -why?

Names Default to Here( 1 );
Clear Symbols();
getDataTable = getDataTable4partID("partID","partIDname"); 
include ("plotallcharts.jsl"); 
include ("generateJournal.jsl");

I assume that this is your first section of your code. Correct?

Your third line in the code is looking for a function called "getDataTable4partID".  That function has not been defined when the code attempts to run that line.  You need to have the function definition executed before it can be called.

Jim
Neo
Neo
Level VI

Re: Running a script after making a change. Not working without closing and re-opening the script -why?

@txnelson 

The function getDataTable4partID has been defined, saved and executed. It was working as expected before.

No longer and also not working are the main script calling it or the other included script in the main script. 

When it's too good to be true, it's neither
Neo
Neo
Level VI

Re: Running a script after making a change. Not working without closing and re-opening the script -why?

Adding 

include ("getDataTable4partID.jsl");

before the function call (getDataTable4partID.jsl being the name of the function script)

 

getDataTable = getDataTable4partID("partID","partIDname"); 

i.e.

 

Names Default to Here( 1 );
Clear Symbols();
include (''getDataTable4partID.jsl");
getDataTable = getDataTable4partID("partID","partIDname"); 
include ("plotallcharts.jsl"); 
include ("generateJournal.jsl");

seems to have solved all the issues. What is the reason?

 

When it's too good to be true, it's neither
txnelson
Super User

Re: Running a script after making a change. Not working without closing and re-opening the script -why?

The function needs to be parsed before it can be called.  The JSL interpreter steps down through the code one line at a time.  If it has not stepped through the function code before you attempt to call that function, JSL will stop.  The same is true for all variable etc. in JSL. Thus:

Names Default to Here( 1 );
Clear Symbols();
print( a );
a = 42;

Will fail with

Name Unresolved: a in access or evaluation of 'a' , a/*###*/

at line 3 in Script 4.jsl

While

Names Default to Here( 1 );
Clear Symbols();
a = 42;
print( a );

will run without error

Jim
Neo
Neo
Level VI

Re: Running a script after making a change. Not working without closing and re-opening the script -why?

Please excuse me for my ignorance, but is this your explanation for why I need to use 

include ("getDataTable4partID.jsl");

for my function call to work?

When it's too good to be true, it's neither