cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-523649%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3EIs%20there%20any%20way%20to%20create%20a%20multi-layer%20array%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-523649%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1)%20I'm%20trying%20to%20create%20a%20multilayer%20array%20where%20one%20key%2C%20gets%20multiple%20layers.%20Is%20there%20any%20way%20to%20do%20this.%20For%20example%2C%20my%20jsl%20should%20look%20like%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEX%20%3D%20Associative%20Array(%20%7B%22Blue%22%2C%20%22Green%22%2C%20%22Red%22%7D%2C%20%7B1%2C%202%2C%203%7D%2C%20%7B%22Bear%22%2C%20%22Gecko%22%2C%20%22Rabbit%22%7D%20)%3B%3C%2FP%3E%3CP%3EI'm%20trying%20to%20get%20it%20so%20that%20if%20I%20select%20%22Blue%22%2C%20I%20get%20both%201%20and%20%22Bear%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E2)%20Is%20there%20any%20way%20for%20an%20array%20to%20map%20for%20a%20function.%20For%20example%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEX%20%3D%20Associative%20Array(%20%7B%22Blue%22%2C%20%22Green%22%7D%2C%20%7BfunctionA%2C%20functionB%7D%20)%3B%3C%2FP%3E%3CP%3EIs%20there%20a%20way%20that%20the%20value%20returned%20triggers%20a%20function%3F%20I've%20tried%20and%20the%20values%20I%20get%20are%20in%20terms%20of%20string%20i.e%20if%20I%20select%20%22Blue%22%2C%20I%20get%20the%20string%20%22functionA%22%20instead%20of%20it%20executing%20functionA.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-523649%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CLINGO-LABEL%3EAdvanced%20Statistical%20Modeling%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAutomation%20and%20Scripting%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EData%20Exploration%20and%20Visualization%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-523673%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Is%20there%20any%20way%20to%20create%20a%20multi-layer%20array%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-523673%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EUnfortunately%20JMP%20does%20not%20offer%20a%20%3CCODE%20class%3D%22%20language-jsl%22%3Ezip()%3C%2FCODE%3E%20function%20for%20lists%2C%20but%20you%20can%20easily%20make%20one%20as%20a%20solution%20to%20your%20first%20item%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Ezip%20%3D%20Function(%20%7Blist%20a%2C%20list%20b%7D%2C%0A%20%7Bzipped%2C%20i%7D%2C%0A%20zipped%20%3D%20%7B%7D%3B%0A%20Summation(%20i%20%3D%201%2C%20Min(%20Length(%20list%20a%20)%2C%20Length(%20list%20b%20)%20)%2C%0A%20%20zipped%5Bi%5D%20%3D%20Eval%20List(%20%7Blist%20a%5Bi%5D%2C%20list%20b%5Bi%5D%7D%20)%3B%0A%20%200%0A%20)%3B%0A%20zipped%0A)%3B%0A%0AEX%20%3D%20Associative%20Array(%20%7B%22Blue%22%2C%20%22Green%22%2C%20%22Red%22%7D%2C%20zip(%20%7B1%2C%202%2C%203%7D%2C%20%7B%22Bear%22%2C%20%22Gecko%22%2C%20%22Rabbit%22%7D%20)%20)%3B%0AShow(%20ex%20)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EFor%20your%20second%20item%2C%20see%20the%20function%20%3CCODE%20class%3D%22%20language-jsl%22%3EName%20Expr()%3C%2FCODE%3E%20--%20it%20should%20do%20what%20you%20want.%26nbsp%3B%20Note%20however%20that%20due%20to%20limitations%20of%20the%20JSL%20parser%2C%20you%20will%20have%20to%20first%20set%20a%20temporary%20variable%20for%20the%20function%20to%20land%20in%2C%20then%20call%20from%20that%20temporary%20variable.%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Ezip%20%3D%20Function(%20%7Blist%20a%2C%20list%20b%7D%2C%0A%20%7Bzipped%2C%20i%7D%2C%0A%20zipped%20%3D%20%7B%7D%3B%0A%20Summation(%20i%20%3D%201%2C%20Min(%20Length(%20list%20a%20)%2C%20Length(%20list%20b%20)%20)%2C%0A%20%20zipped%5Bi%5D%20%3D%20Eval%20List(%20%7Blist%20a%5Bi%5D%2C%20list%20b%5Bi%5D%7D%20)%3B%0A%20%200%0A%20)%3B%0A%20zipped%0A)%3B%0A%0AEX%20%3D%20%5B%3D%26gt%3B%5D%3B%0AEX%5B%22zip%22%5D%20%3D%20Name%20Expr(%20zip%20)%3B%0A%0Afunc%20%3D%20ex%5B%22zip%22%5D%3B%0AShow(%20func(%20%7B1%2C%202%2C%203%7D%2C%20%7B%22Bear%22%2C%20%22Gecko%22%2C%20%22Rabbit%22%7D%20)%20)%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-523678%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Is%20there%20any%20way%20to%20create%20a%20multi-layer%20array%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-523678%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EJust%20another%20way%20to%20implement%20would%20be%20the%20following%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0A%0A%2F%2F%20nested%20structure%0AEX%20%3D%20Associative%20Array(%20%7B%22Blue%22%2C%20%22Green%22%2C%20%22Red%22%7D%2C%20%7B%7B1%2C%20%22Bear%22%7D%2C%20%7B2%2C%20%2C%20%22Gecko%22%7D%2C%20%7B3%2C%20%22Rabbit%22%7D%7D%20)%3B%0AShow(%20EX%5B%22Blue%22%5D%20)%3B%0A%0A%2F%2F%20Function%20example%0Amyadd%20%3D%20Function(%20%7Bop1%2C%20op2%7D%2C%0A%20op1%20%2B%20op2%0A)%3B%0Amymult%20%3D%20Function(%20%7Bop1%2C%20op2%7D%2C%0A%20op1%20*%20op2%0A)%3B%0A%0Afunc_aa%20%3D%20Associative%20Array(%20%7B%22add%22%2C%20%22mult%22%7D%2C%20%7Bmyadd%2C%20mymult%7D%20)%3B%0Amyfunc%20%3D%20func_aa%5B%22add%22%5D%3B%0AShow(%20myfunc(%201%2C%202%20)%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
PowerOx327
Level I

Is there any way to create a multi-layer array?

Hi,

 

1) I'm trying to create a multilayer array where one key, gets multiple layers. Is there any way to do this. For example, my jsl should look like:

 

EX = Associative Array( {"Blue", "Green", "Red"}, {1, 2, 3}, {"Bear", "Gecko", "Rabbit"} );

I'm trying to get it so that if I select "Blue", I get both 1 and "Bear".

 

2) Is there any way for an array to map for a function. For example,

 

EX = Associative Array( {"Blue", "Green"}, {functionA, functionB} );

Is there a way that the value returned triggers a function? I've tried and the values I get are in terms of string i.e if I select "Blue", I get the string "functionA" instead of it executing functionA. 

 

 

 

 

2 REPLIES 2
ErraticAttack
Level VI

Re: Is there any way to create a multi-layer array?

Unfortunately JMP does not offer a zip() function for lists, but you can easily make one as a solution to your first item:

 

zip = Function( {list a, list b},
	{zipped, i},
	zipped = {};
	Summation( i = 1, Min( Length( list a ), Length( list b ) ),
		zipped[i] = Eval List( {list a[i], list b[i]} );
		0
	);
	zipped
);

EX = Associative Array( {"Blue", "Green", "Red"}, zip( {1, 2, 3}, {"Bear", "Gecko", "Rabbit"} ) );
Show( ex )

For your second item, see the function Name Expr() -- it should do what you want.  Note however that due to limitations of the JSL parser, you will have to first set a temporary variable for the function to land in, then call from that temporary variable.

zip = Function( {list a, list b},
	{zipped, i},
	zipped = {};
	Summation( i = 1, Min( Length( list a ), Length( list b ) ),
		zipped[i] = Eval List( {list a[i], list b[i]} );
		0
	);
	zipped
);

EX = [=>];
EX["zip"] = Name Expr( zip );

func = ex["zip"];
Show( func( {1, 2, 3}, {"Bear", "Gecko", "Rabbit"} ) )
Jordan
Georg
Level VII

Re: Is there any way to create a multi-layer array?

Just another way to implement would be the following:

Names Default To Here( 1 );

// nested structure
EX = Associative Array( {"Blue", "Green", "Red"}, {{1, "Bear"}, {2, , "Gecko"}, {3, "Rabbit"}} );
Show( EX["Blue"] );

// Function example
myadd = Function( {op1, op2},
	op1 + op2
);
mymult = Function( {op1, op2},
	op1 * op2
);

func_aa = Associative Array( {"add", "mult"}, {myadd, mymult} );
myfunc = func_aa["add"];
Show( myfunc( 1, 2 ) );
Georg

Recommended Articles