<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Expression Indexing: How to climb the Expression Tree? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Expression-Indexing-How-to-climb-the-Expression-Tree/m-p/697406#M88295</link>
    <description>&lt;P&gt;This post was born as a wishlist entry - but it turns out that the wish is already partially possible (see &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;'s answer below).&lt;BR /&gt;So I moved it here to make the results more visible.&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;The original wish - which asks for a functionality which goes beyond what is already possible - can be found here:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;LI-MESSAGE title="Expression Indexing: read and write access" uid="697359" url="https://community.jmp.com/t5/JMP-Wish-List/Expression-Indexing-read-and-write-access/m-p/697359#U697359" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-idea-thread lia-fa-icon lia-fa-idea lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Please have a look and decide if it could help you as well ...&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;___________________________________________&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;In many programming languages, one can index lists and matrices. This is also possible in Jmp:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;&lt;CODE class=" language-jsl"&gt;list= {"A", "B", "C"};
mat=[1,2,3];
list[3]
mat[2]&lt;/CODE&gt;&lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;With Jmp 13, another level of indexing got possible: &lt;LI-MESSAGE title="Data table subscripting" uid="21013" url="https://community.jmp.com/t5/Uncharted/Data-table-subscripting/m-p/21013#U21013" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;BR /&gt;Nowadays the User can easily index entries in the data table with read and write access.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a third kind of indexing: Display Tree Indexing&lt;BR /&gt;For a given Report, you can walk down the Display Tree to identify a specific object:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = dt &amp;lt;&amp;lt; 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)]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe there are more places in Jmp where indexing helps the user with his daily work ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For Expressions it's much more complicated to walk down the tree:&lt;/P&gt;&lt;P&gt;To get the Y variable &lt;FONT face="courier new,courier"&gt;:weight&amp;nbsp;&lt;/FONT&gt;from&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;myExpr=Expr(gb = dt &amp;lt;&amp;lt; 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 ) ) )
));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;one has to use&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Arg(Arg(Arg(Arg(Arg(myExpr,2),2),3),2),1)  // :weight&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;very fragile !!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A workaround: convert the &lt;FONT face="courier new,courier"&gt;Variables&lt;/FONT&gt; Expression into a list and use &lt;EM&gt;List&lt;/EM&gt;-indexing:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;myExpr=Expr(Variables( X( :height ), Y( :weight ), Overlay( :sex ) ))
Substitute(Name Expr(myExpr),Expr(Variables()),Expr(List()))["Y"];&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but there are several disadvantages:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;just works for a single level - flat hierarchy&lt;/LI&gt;&lt;LI&gt;just the first named argument is found, further named arguments with the same identifier are ignored:&lt;BR /&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;myExpr=Expr(Variables( X( :height ), Y( :weight ),Y(:height ), Overlay( :sex ) )); 
Substitute(Name Expr(myExpr),Expr(Variables()),Expr(List()))["Y"];&amp;nbsp;//&amp;nbsp;returns&amp;nbsp;:weight,&amp;nbsp;ignores&amp;nbsp;Y(:height)&lt;/CODE&gt;&lt;/PRE&gt;&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;just returns the first argument, further arguments get lost&lt;BR /&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;myExpr = Expr(Distribution(columns(:height, :weight)));
Substitute(Name Expr(myExpr),Expr(Distribution()),Expr(List()))["columns"];
//returns :height -&amp;gt; :weight gets lost&lt;/CODE&gt;&lt;/PRE&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a possibility, analogous to Display Tree Indexing, to&amp;nbsp;climbing an Expression Tree?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;instead of&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
myExpr=Expr(gb = dt &amp;lt;&amp;lt; 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)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to use&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;myExpr[2][2["Variables"]["Y"(2)][1]&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 18 Sep 2024 21:38:58 GMT</pubDate>
    <dc:creator>hogi</dc:creator>
    <dc:date>2024-09-18T21:38:58Z</dc:date>
    <item>
      <title>Expression Indexing: How to climb the Expression Tree?</title>
      <link>https://community.jmp.com/t5/Discussions/Expression-Indexing-How-to-climb-the-Expression-Tree/m-p/697406#M88295</link>
      <description>&lt;P&gt;This post was born as a wishlist entry - but it turns out that the wish is already partially possible (see &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;'s answer below).&lt;BR /&gt;So I moved it here to make the results more visible.&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;The original wish - which asks for a functionality which goes beyond what is already possible - can be found here:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;LI-MESSAGE title="Expression Indexing: read and write access" uid="697359" url="https://community.jmp.com/t5/JMP-Wish-List/Expression-Indexing-read-and-write-access/m-p/697359#U697359" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-idea-thread lia-fa-icon lia-fa-idea lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Please have a look and decide if it could help you as well ...&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;___________________________________________&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;In many programming languages, one can index lists and matrices. This is also possible in Jmp:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;&lt;CODE class=" language-jsl"&gt;list= {"A", "B", "C"};
mat=[1,2,3];
list[3]
mat[2]&lt;/CODE&gt;&lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;With Jmp 13, another level of indexing got possible: &lt;LI-MESSAGE title="Data table subscripting" uid="21013" url="https://community.jmp.com/t5/Uncharted/Data-table-subscripting/m-p/21013#U21013" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;BR /&gt;Nowadays the User can easily index entries in the data table with read and write access.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a third kind of indexing: Display Tree Indexing&lt;BR /&gt;For a given Report, you can walk down the Display Tree to identify a specific object:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = dt &amp;lt;&amp;lt; 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)]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe there are more places in Jmp where indexing helps the user with his daily work ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For Expressions it's much more complicated to walk down the tree:&lt;/P&gt;&lt;P&gt;To get the Y variable &lt;FONT face="courier new,courier"&gt;:weight&amp;nbsp;&lt;/FONT&gt;from&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;myExpr=Expr(gb = dt &amp;lt;&amp;lt; 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 ) ) )
));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;one has to use&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Arg(Arg(Arg(Arg(Arg(myExpr,2),2),3),2),1)  // :weight&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;very fragile !!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A workaround: convert the &lt;FONT face="courier new,courier"&gt;Variables&lt;/FONT&gt; Expression into a list and use &lt;EM&gt;List&lt;/EM&gt;-indexing:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;myExpr=Expr(Variables( X( :height ), Y( :weight ), Overlay( :sex ) ))
Substitute(Name Expr(myExpr),Expr(Variables()),Expr(List()))["Y"];&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but there are several disadvantages:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;just works for a single level - flat hierarchy&lt;/LI&gt;&lt;LI&gt;just the first named argument is found, further named arguments with the same identifier are ignored:&lt;BR /&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;myExpr=Expr(Variables( X( :height ), Y( :weight ),Y(:height ), Overlay( :sex ) )); 
Substitute(Name Expr(myExpr),Expr(Variables()),Expr(List()))["Y"];&amp;nbsp;//&amp;nbsp;returns&amp;nbsp;:weight,&amp;nbsp;ignores&amp;nbsp;Y(:height)&lt;/CODE&gt;&lt;/PRE&gt;&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;just returns the first argument, further arguments get lost&lt;BR /&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;myExpr = Expr(Distribution(columns(:height, :weight)));
Substitute(Name Expr(myExpr),Expr(Distribution()),Expr(List()))["columns"];
//returns :height -&amp;gt; :weight gets lost&lt;/CODE&gt;&lt;/PRE&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a possibility, analogous to Display Tree Indexing, to&amp;nbsp;climbing an Expression Tree?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;instead of&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
myExpr=Expr(gb = dt &amp;lt;&amp;lt; 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)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to use&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;myExpr[2][2["Variables"]["Y"(2)][1]&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Sep 2024 21:38:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Expression-Indexing-How-to-climb-the-Expression-Tree/m-p/697406#M88295</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2024-09-18T21:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: Expression Indexing: How to climb the Expression Tree?</title>
      <link>https://community.jmp.com/t5/Discussions/Expression-Indexing-How-to-climb-the-Expression-Tree/m-p/697462#M88298</link>
      <description>&lt;P&gt;There are some options on how you can do this already (but expression subscripting could be useful). Like I did mention in the wish list item (&lt;A href="https://community.jmp.com/t5/JMP-Wish-List/Expression-Indexing-Help-me-climbing-the-Expression-Tree/idc-p/697370/highlight/true#M5031" target="_blank"&gt;Expression Indexing: Help me climbing the Expression Tree - JMP User Community&lt;/A&gt;), JMP does have Extract Expr() which uses Wild() and Wild List()&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

myExpr = Expr(
	gb = dt &amp;lt;&amp;lt; 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)))
	)
);

yexpr = Extract Expr(myExpr, Y(Wild()));
variables_expr = Extract Expr(myExpr, Variables(Wild List()));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

myExpr = Expr(
	gb = dt &amp;lt;&amp;lt; 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)))
	)
);

variables_expr = Extract Expr(myExpr, Variables(Wild List()));
idx = 0;
For(i = 1, i &amp;lt;= N Arg(variables_expr), i++,
	firstlevel = Arg(variables_expr, i); // could use Extract Expr
	If(Head(firstlevel) == Expr(Y) &amp;amp; idx == 2,
		secondlevel = Arg(firstlevel, 1);
	);
);
show(secondlevel);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There are also other things you can do (but not really sure if you should)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

myExpr = Expr(
	Variables(X(:height), Y(:weight), Y(:height), Overlay(:sex))
);

listconversion = Substitute(Name Expr(myExpr), Expr(Variables()), Expr(List())); 

yexprs = {};
While(yexpr = Contains(listconversion, Extract Expr(listconversion, Y(Wild()))),
	Insert Into(yexprs, Remove From(listconversion, yexpr));
);
show(yexprs);
yexprs[2];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There could be other weird stuff you could do with lists...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.jmp.com/support/help/en/17.2/#page/jmp/advanced-expressions-macros-and-lists.shtml#ww339382" target="_blank"&gt;Advanced Expressions, Macros, and Lists (jmp.com)&lt;/A&gt;&amp;nbsp;can be a good read&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2023 14:38:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Expression-Indexing-How-to-climb-the-Expression-Tree/m-p/697462#M88298</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-11-13T14:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: Expression Indexing: How to climb the Expression Tree?</title>
      <link>https://community.jmp.com/t5/Discussions/Expression-Indexing-How-to-climb-the-Expression-Tree/m-p/825868#M100647</link>
      <description>&lt;P&gt;Thanks, &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;Extract Expr()&lt;/FONT&gt; is very helpful to get to the correct level of the tree.&lt;BR /&gt;It helped me a lot last year : )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just noticed that the processing of arguments within one level can be done much easier:&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;For Each&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;Transform Each&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;Filter Each&lt;/FONT&gt; can be used with expressions. Cool!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1735977771997.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/71689i1297185BCF9D7689/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_0-1735977771997.png" alt="hogi_0-1735977771997.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Main Script = Expr(dt &amp;lt;&amp;lt; Graph Builder(
	Size( 437, 413 ),
	Graph Spacing( 4 ),
	Variables( X( :height ), Y( :weight ), Y (:sex), Overlay( :sex ) ),
	Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) )
));

snippet = Extract Expr(Main Script, Variables(Wild List()))

For each({variable}, Name Expr(snippet), Show(Head(variable), Arg(variable)))

selection = Filter Each ({code}, Name Expr(snippet), Head(code)==Expr(Y()));
Show(selection)

changed= Transform Each ({code}, Name Expr(snippet), If (Head(code)==Expr(X()),  Expr(my changed code),Name Expr(code)))
Show(changed);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jan 2025 08:08:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Expression-Indexing-How-to-climb-the-Expression-Tree/m-p/825868#M100647</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2025-01-04T08:08:32Z</dc:date>
    </item>
  </channel>
</rss>

