Choose Language Hide Translation Bar
Highlighted
miguello
Community Trekker

Trying to use Include Files List()

Hello all, 

 

I'm trying to use Include File List() and I'm getting errors. It is not working as I would have expected.

Here is an example.

I have 3 files files named Include1.jsl, Include2.jsl, Include3.jsl that I'm trying to include into TestInclude.jsl that is listed below:

 

Clear Log();
//Names Default To Here( 1 );
Clear Symbols();
Clear Globals();

Include( "Include1.jsl" );
Include( "Include2.jsl" );
Include( "Include3.jsl" );


show(Include File List());

All four files are in the same folder.  Each of the three included files have their corresponding 

show("IncludeScriptN");

where N is 1, 2 and 3

When I'm running the TestInclude,jsl, I'm expecting to see:

"IncludeScript1";
"IncludeScript2";
"IncludeScript3";
Include File List() = {"C:\...\TestingLocaleScipts\TestInclude.jsl", "C:\...\TestingLocaleScipts\Include1.jsl", "C:\...\TestingLocaleScipts\Include2.jsl", "C:\...\TestingLocaleScipts\Include3.jsl"};

Instead I see this:

"IncludeScript1";
"IncludeScript2";
"IncludeScript3";
Include File List() = {"C:\...\TestingLocaleScipts\TestInclude.jsl"}

So, included files ARE indeed included, they DO indeed work, but function does not show them? What am I doing wrong?

 

Thanks, 

M.

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Staff (Retired)

Re: Trying to use Include Files List()

The function returns the current nesting of included files. At the root level, where you've called it, there is only one file, no actual nesting. Try calling it from one of the included files.

 

fn1 = Save Text File( "$temp/a.jsl", "show(Include File List())" );
fn2 = Save Text File( "$temp/b.jsl", "include(fn1)" );
Include( fn2 );

Include File List() = {"C:\Users\v1\AppData\Local\Temp\a.jsl", "C:\Users\v1\AppData\Local\Temp\b.jsl", "Script.jsl"};

script.jsl is the name of the unsaved root-level script.

 

The function is for implementing custom error reporting; if something goes wrong in a try() in the fn1 file, you can write the catch clause to report the nested includes. As a cool side effect, it also gives you the name of the current script file.

 

There are two ways to use include files: you might think of them as function libraries, or you might think of them as blocks of code to execute. The Include File List is not very useful if they are function libraries because most of the code is not executing while the include is running...it defines the functions and returns. But if the include file is a block of code that runs when included, and might include more blocks of code, then Include File List might be helpful for debugging.

Craige

View solution in original post

4 REPLIES 4
Craige_Hales
Staff (Retired)

Re: Trying to use Include Files List()

The function returns the current nesting of included files. At the root level, where you've called it, there is only one file, no actual nesting. Try calling it from one of the included files.

 

fn1 = Save Text File( "$temp/a.jsl", "show(Include File List())" );
fn2 = Save Text File( "$temp/b.jsl", "include(fn1)" );
Include( fn2 );

Include File List() = {"C:\Users\v1\AppData\Local\Temp\a.jsl", "C:\Users\v1\AppData\Local\Temp\b.jsl", "Script.jsl"};

script.jsl is the name of the unsaved root-level script.

 

The function is for implementing custom error reporting; if something goes wrong in a try() in the fn1 file, you can write the catch clause to report the nested includes. As a cool side effect, it also gives you the name of the current script file.

 

There are two ways to use include files: you might think of them as function libraries, or you might think of them as blocks of code to execute. The Include File List is not very useful if they are function libraries because most of the code is not executing while the include is running...it defines the functions and returns. But if the include file is a block of code that runs when included, and might include more blocks of code, then Include File List might be helpful for debugging.

Craige

View solution in original post

vince_faller
Super User

Re: Trying to use Include Files List()

@Craige_Hales 

Retired and still working?

Can you explain what you mean with the custom error reporting?  Are you saying just for what script the error happened in?  

Because I thought the main function was to show you what script you're in at the time of call.  

If all of your child scripts are only functions that don't run, then you don't actually see the include file list() nesting right? 

 

Names default to here(1);
fn1 = Save Text File( "$temp/a.jsl", "show(Include File List()); f2 = function({}, include file list());" );
fn2 = Save Text File( "$temp/b.jsl", "include(fn1); f = function({}, include file list());" );
Include( fn2 );
show(f(), f2());
Vince Faller - Predictum
0 Kudos
Craige_Hales
Staff (Retired)

Re: Trying to use Include Files List()

@vince_faller Pretty sure calling IncludeFileList from a user defined function has to return the current stack of include files and not the stack that existed when the function was being defined. As your example hints, you can capture the stack at function definition time by executing IncludeFileList within the included file, but outside of a function definition.

I do think one of the best use cases is to get the name of the current file from list item 1.

 

Craige
0 Kudos
miguello
Community Trekker

Re: Trying to use Include Files List()

Understood. Thanks a lot. Explanation in the scripting index or help is definitely not enough to understand which way the nesting goes: either it's all the scripts that are included into a script it's been called form or all the scripts that come from where it called to the root one.
0 Kudos