:folded_hands: 表達式索引:讀寫訪問☑ 很酷的新功能
可以幫助很多用戶!
刪除一個“bug”
很高興擁有
無人需要它
是什麼激發了這個願望清單請求?
編輯:第一部分轉移到表達式索引:如何爬表達式樹?
感謝@jthi提供解決方案:
透過擷取表達式使用者可以搜尋和提取部分錶達式。
此函數提供模式搜尋並傳回第一個符合項。
甚至可以使用通配符
您希望看到什麼改進?
顯示樹索引和資料表索引的混合 - 僅適用於表達式:
透過以下方式進行更精確的讀取存取:
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 ,例如:
Insert Into ( myExpr["Variables"], Expr(Y(:age)))
為什麼這個想法很重要?
借助表達式索引的強大功能,Jmp 中的表達式處理將變得更加容易:)
更多願望提交者
自動化和腳本編寫回覆:表達式索引:讀寫存取 - 狀態變更為:已確認回覆:表達式索引:讀寫訪問JMP Expr() 的奇怪之處,有人能解釋一下嗎?
對於Insert Into ,除了目前的 Turbo 模式外,還提供額外的「非合併」模式....
Turbo 模式(如「插入」現在的行為):
如果要插入的表達式的標頭與目標位置上方層級的標頭相同,則該表達式將與更高層級「合併」。
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 使用者不會使用它:實現願望的希望渺茫。
雕刻出插入到的願望: 插入到:Flatten(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 !
太棒了 - Extract expr - 比我透過Substitute (... List) 的解決方法好得多:
-> 修復問題 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: 表達式索引:讀寫訪問表達式索引的另一個應用程式 - 寫入模式:
替換頭()?
已有一個願望可用: 替代第一次出現
是的,請:)
回覆::folded_hands: 表達式索引:讀寫訪問最重要的用例已經可用或已製定。
@Sarah-Sylvestre ,狀態可能設定為 暫時沒有計劃