This post was born as a wishlist entry - but it turns out that the wish is already partially possible (see @jthi's answer below).
So I moved it here to make the results more visible.
The original wish - which asks for a functionality which goes beyond what is already possible - can be found here:
Expression Indexing: read and write access
Please have a look and decide if it could help you as well ...
___________________________________________
In many programming languages, one can index lists and matrices. This is also possible in Jmp:
list= {"A", "B", "C"};
mat=[1,2,3];
list[3]
mat[2]
With Jmp 13, another level of indexing got possible: Data table subscripting
Nowadays the User can easily index entries in the data table with read and write access.
There is a third kind of indexing: Display Tree Indexing
For a given Report, you can walk down the Display Tree to identify a specific object:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = dt << Graph Builder(
Size( 437, 413 ),
Graph Spacing( 4 ),
Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),
Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) )
)
Report(gb)["Graph Builder"][AxisBox(1)]
Maybe there are more places in Jmp where indexing helps the user with his daily work ...
For Expressions it's much more complicated to walk down the tree:
To get the Y variable :weight from
myExpr=Expr(gb = dt << Graph Builder(
Size( 437, 413 ),
Graph Spacing( 4 ),
Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),
Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) )
));
one has to use
Arg(Arg(Arg(Arg(Arg(myExpr,2),2),3),2),1) // :weight
very fragile !!!!
A workaround: convert the Variables Expression into a list and use List-indexing:
myExpr=Expr(Variables( X( :height ), Y( :weight ), Overlay( :sex ) ))
Substitute(Name Expr(myExpr),Expr(Variables()),Expr(List()))["Y"];
but there are several disadvantages:
- just works for a single level - flat hierarchy
- just the first named argument is found, further named arguments with the same identifier are ignored:
myExpr=Expr(Variables( X( :height ), Y( :weight ),Y(:height ), Overlay( :sex ) ));
Substitute(Name Expr(myExpr),Expr(Variables()),Expr(List()))["Y"]; // returns :weight, ignores Y(:height)
- just returns the first argument, further arguments get lost
myExpr = Expr(Distribution(columns(:height, :weight)));
Substitute(Name Expr(myExpr),Expr(Distribution()),Expr(List()))["columns"];
//returns :height -> :weight gets lost
Is there a possibility, analogous to Display Tree Indexing, to climbing an Expression Tree?
instead of
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
myExpr=Expr(gb = dt << Graph Builder(
Size( 437, 413 ),
Graph Spacing( 4 ),
Variables( X( :height ), Y( :weight ), Y(:height), Overlay( :sex ) ),
Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) )
));
//instead of:
Arg(Arg(Arg(Arg(Arg(myExpr,2),2),3),3),1)
I want to use
myExpr[2][2["Variables"]["Y"(2)][1]