cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar

JSL Basics

Lets face it, JSL isn't the most user friendly language to use. It is mostly designed for you to back up your data after working on a lengthy project. With that being said, there are many usefull things you can do with it. This thread is dedicated to the basics of JSL. If I leave out some things, and I will, please feel free to reply and help out the users of JMP, so it isn't as hard as it was for me to learn JSL.

Functions:
Functions are a good way of reusing code if you need to use it over and over. The functions in JSL have all the things you would expect, a specific user set name, input parameters, and a return value. This function also shows how to parse a comma delimited text file. Syntax below.

funcName = Function( {param1},
	{return1},
	textFile = Load Text File( param1 ); // Reads a text File called param1
	// Parses through the file which is comma delimited and gets a list of words
	return1 = Words( textFile, "," );
);

To Call the function and assign the return value:
wordss = funcName( "fileName.txt" )
If Statemens:
The if statement works sort of like you would expect, but the syntax is a little different. Here is an example:

For Loops:
The for loops are very similar to the traditional for loop. It has the three part syntax with the chunk that gets looped. The first chunk is for initialization, the second is conditional, the third is the "Do after loop" chunk. It will make more sense in a second.
In JSL a fourth chunk is added which is all statements to be executed. Syntax below:

This is just the basics, I will add more to this thread later. Hopefully people contribute to make it very benificial. Thanks all.
-KaptainKodie

6 REPLIES 6
ms
Super User (Alumni) ms
Super User (Alumni)

Re: JSL Basics

Thanks Kaptain,

I will eagerly follow this thread. I am just about to translate a massive excel vba macro to jsl (vba is currently a no-no on the mac) and I appreciate that you share your insights with us. It will definately speed up learning the jsl basics (and beyond).

Right now I am frustratingly trying to find a way to automate export of graphs etc. in eps or pdf to facilitate import into Adobe Illustrator for giving the final touches to the graphics. I have managed to get around this problem via the save as pict which retains the vectors and fonts but the result is not perfect or very predictable.
pmroz
Super User

Re: JSL Basics

Thanks for the tips Kaptain. I'm an experienced programmer but JSL still throws me a loop every once in a while. Here are some of my experiences:

I use functions now and then, but they don't always operate the same way as the JSL code in your "main" routine. I have a function that does a tabulation and then an optional sort on a dataset. To get it to work I had to use many calls to expr, eval and eval expr. Took many emails to the help desk to get it to finally work.

I've switched over to using a different approach, namely include files. Instead of calling a function I do this:



The Get Dataset.JSL program resides in the same directory as the calling program. It sets the variable current_dataset. The advantage of this approach is that I no longer need complex calls to eval, eval expr and expr. The call to THROW halts execution of the main program.

Message was edited by: PMroz
pmroz
Super User

Re: JSL Basics

One more tip regarding IF statements. They can be confusing to read
later on, so I use a lot of comments to help. Using your example:




style="font-family: Courier New;">n = 3;


style="font-family: Courier New;">
If
( n < 0,


style="font-family: Courier New;">
   
// then


style="font-family: Courier New;">
   
print ( "Less than 0" );


style="font-family: Courier New;">
   
print ( "This example is weak" ),


style="font-family: Courier New;">
   
// else if


style="font-family: Courier New;">
   
n > 0,


style="font-family: Courier New;">
   
// then


style="font-family: Courier New;">
   
print ( "Greater than 0" ),


style="font-family: Courier New;">
   
// else


style="font-family: Courier New;">
   
print ( "Is Zero" )


style="font-family: Courier New;">
   
);






This is a relatively simple example, but this technique helps me (and
other programmers!) understand complex code, especially after not
looking at it for a while.




Message was edited by: PMroz

Re: JSL Basics

I normally just use tabs for indenting all my IF statements, but I'm going to try that comment thing to make it easier to read. That should help a lot! Thanks!

Formula evaluations in JSL

This was my earliest problem in JSL. Forcing the table to evaluate formulas before continuing.

Before adding a bunch of formula columns, do the following:
dt << suppress formula eval(1) << ;
dt << suppress formula eval(0) << run formulas(); //put this after the new columns

Otherwise future operations on the table/rows/columns/values may run before it's done with the formulas on every row. This caused me a lot of heartache when I first started JSL.
gh
gh
Level III

Re: Formula evaluations in JSL

I don't do the suppress formula, but I ALWAYS do dt<
Good thread. I think it would be great if more people used JSL. It's quite powerful, but not documented well enough in my opinion and so can be a bit tricky to use. It also tends to change from version to version and so your scripts can break even going from x.01 to x.02.