:folded_hands: 表达式索引:读写访问☑ 很酷的新功能
☐ 可以帮助很多用户!
☐ 删除“错误”
☐ 很高兴有
☐ 没人需要它
是什么启发了这个愿望清单请求?
编辑:第一部分转移到表达式索引:如何爬上表达式树?
感谢@jthi提供解决方案:
通过提取 expr用户可以搜索并提取表达式的部分内容。
该函数提供模式搜索并返回第一个匹配项。
甚至通配符也是可能的
您希望看到什么改进?
显示树索引和数据表索引的混合-仅适用于表达式:
通过以下方式实现更精确的读取访问:
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)
<BR />// I want to use:
myExpr[2][2]["Variables"]["Y"(2)][1]
//assign // send // Graph Builder // Variables<BR /><BR />// or like it's possible for Display Trees:<BR />myExpr["Variables"]["Y"(2)][1]
真正酷的地方是:写访问类似于通过数据表索引可以实现的访问:
myExpr["Variables"]["Y"(2)][1] = Expr(:height);
就像替代品——但是在不同的维度!
[编辑]
也许表达式索引的最佳应用是:插入,例如:
Insert Into ( myExpr["Variables"], Expr(Y(:age)))
为什么这个想法很重要?
借助表达式索引的强大功能,Jmp 中的表达式处理将变得更加容易:)
更多愿望由
自动化和脚本回复:表达式索引:读写访问 - 状态更改为:已确认回复:表达式索引:读写访问JMP Expr() 很奇怪,有人能解释一下吗?
对于插入,除了当前的涡轮模式之外,请提供额外的“非合并”模式......
涡轮模式(如“插入”现在的行为):
如果要插入的表达式的头部与目标位置上一级的头部相同,则该表达式将与更高级别“合并”。
Insert Into (List(a,b), List(c,d)) // {a,b,c,d}附加非合并模式:
Insert Into (List(a,b), List(c,d), merge(0)) // {a,b,{c,d}}
由于设置表达式索引需要付出很大努力,而且大多数 JMP 用户不会使用它:因此实现这一愿望的希望很小。
雕刻愿望插入到: 插入到:展平(0|1)
回复:表达式索引:帮助我爬上表达式树感谢@Craige_Hales提供的很好的例子:)
我希望其他人也会支持这个想法......
回复:表达式索引:帮助我爬上表达式树您将如何转换它
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)))
)
);
对此?
myExpr = Expr(
gb = dt << Graph Builder(
Size(437, 413),
Graph Spacing(4),
Variables(X(:height), Y(:weight), /*added:*/ Y(:height), Overlay(:sex)),
Elements(Points(X, Y, Legend(1)), Smoother(X, Y, Legend(2)))
)
);
索引可以让它变得容易得多。感觉就像一个 InsertInto( myExpr, ... ) 问题。如果你能弄清楚如何将运算符转换为列表然后再转回来,那就行得通了,但像
InsertInto( myExpr[/* = */ 2][ /* << */ 2]["Variables"], /* insert position*/ 3, expr( Y(:height)))
可以就地编辑表达式。
概念证明:
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 ) ) )
)
);
Show( "Original", Name Expr( myExpr ) );
// convert operators to lists
Substitute Into( myExpr, Expr( Assign() ), {} );
Substitute Into( myExpr[2], Expr( Send() ), {} );
Substitute Into( myExpr[2][2], Expr( Graph Builder() ), {} );
Substitute Into( myExpr[2][2][3], Expr( Variables() ), {} );
// make the edit
Insert Into( myExpr[2][2][3], Expr( Y( :height ) ), 3 );
// reverse the earlier conversions
Substitute Into( myExpr[2][2][3], {}, Expr( Variables() ) );
Substitute Into( myExpr[2][2], {}, Expr( Graph Builder() ) );
Substitute Into( myExpr[2], {}, Expr( Send() ) );
Substitute Into( myExpr, {}, Expr( Assign() ) );
Show( "Edited", Name Expr( myExpr ) );
//
// wouldn't it be nice if we could use the edit line directly?
//
Write( "\!nTry without a list:" );
Insert Into( myExpr[2][2][3], Expr( Y( :height ) ), 3 ); // does not work
// it fails because expressions can't be indexed, even though they
// are extremely similar to lists (as seen above).
// I'm not sure why it needs to be that way.
我们喜欢使用 xxxInto(...) 函数,因为它们可以就地修改现有的表达式树。在某些情况下,这可能是一个效率问题(与复制表达式的片段并重建相比),但将运算符视为列表也更清晰一些。
谢谢@hogi , @jthi
回复:表达式索引:帮助我爬上表达式树@jthi ,有了这个好的解决方案,我认为这个主题在讨论中的位置会更好:
https://community.jmp.com/t5/Discussions/Expression-Indexing-How-to-climbing-the-Expression-Tree/mp/697406
您能否在那里添加您的评论 - 然后我会接受它作为解决方案
回复:表达式索引:帮助我爬上表达式树谢谢@jthi !
太棒了——提取 expr——比我通过替代(...列表)的解决方法好多了:
-> 修复问题 1 和 3
对于问题#2,第二个例子是一个很好的解决方法 - 同时:
说明了表达式索引。
有了Extract expr - 之后,就不再需要紧急读取访问表达式索引了。:)
编辑 :
啊! Extract Expr只找到第一次出现的情况!
回复:表达式索引:帮助我爬上表达式树JMP 确实有 Extract Expr,这使得其中一些更容易
Names Default To Here(1);
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)))
)
);
yexpr = Extract Expr(myExpr, Y(Wild()));
variables_expr = Extract Expr(myExpr, Variables(Wild List()));
Names Default To Here(1);
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)))
)
);
variables_expr = Extract Expr(myExpr, Variables(Wild List()));
idx = 0;
For(i = 1, i <= N Arg(variables_expr), i++,
firstlevel = Arg(variables_expr, i); // could use Extract Expr
If(Head(firstlevel) == Expr(Y) & idx == 2,
secondlevel = Arg(firstlevel, 1);
);
);
show(secondlevel);
回复::folded_hands: 表达式索引:读写访问表达式索引的另一个应用-写入模式:
替换 Head() ?
已有一个可用的愿望: 替换第一次出现
是的 
回复::folded_hands: 表达式索引:读写访问其中最重要的用例已经存在或者已经被开发出来。
@Sarah-Sylvestre ,状态可能设置为 暂时没有计划