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.
Advanced Statistical ModelingAutomation and ScriptingData Exploration and VisualizationRe: 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"} ) )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 ) );