JMP Expr() 的奇怪之處,有人能解釋一下嗎?這主要是一篇關於將“IF”表達式插入“IF”表達式的不一致問題的令人沮喪的帖子。我的理解是,如果不一致,程式語言就毫無意義(而且我知道 JMP 的許多其他不一致之處 - 只是這一點對我來說根本沒有意義)。
/*
What I want is to generate an expression such as the one below programmatically. There of course is a straight-forward work around, I just don't like dealing with special cases especially when they make no sense.
Expr( If( a, If( b, c) ) )<BR />
*/
expr = Expr( If( a ) );
Insert Into( expr, Expr( If( b, c ) ) );
Show( Name Expr( expr ) );
/*
If( a, b, c)
*/
expr = Expr( not an If( a ) );
Insert Into( expr, Expr( If( b, c ) ) );
Show( Name Expr( expr ) );
/*
not an If( a, If( b, c) )
*/
如果有人有任何見解,或者特別是如果您知道一種可靠地將任何表達式插入到任何其他表達式中的方法(不是通過使用“Eval Insert”或字串),那就太好了!謝謝!
進階統計建模回覆:JMP Expr() 怪異,有人能解釋嗎?有一個解決方法可以完成所要求的任務 - 但實際問題是:為什麼?!?尚未得到答覆。
添加到Jmp 和 JSL 中的小陷阱
回覆:JMP Expr() 怪異,有人能解釋嗎?更多的例子很容易反駁一些假設 - 並添加一些進一步的見解:
expr = Expr( If( a, x ) );
Insert Into( expr, Expr(If( b,c )) );
Show( Name Expr( expr ) ); // if(a,x,b,c)
expr = Expr( If( a ) );
Insert Into( expr, Expr(If( b )) );
Show( Name Expr( expr ) ); // if(a,b)
expr = Expr( List( a ) );
Insert Into( expr, Expr(List( b )) );
Show( Name Expr( expr ) ); // List(a,b)
expr = Expr( Graph Builder( a ) );
Insert Into( expr, Expr(Graph Builder ( b )) );
Show( Name Expr( expr ) ); // Graph Builder(a,b)
expr = Expr( Head( a ) );
Insert Into( expr, Expr(Head( b )) );
Show( Name Expr( expr ) ); // Head(a,b) (!)
expr = Expr( Not( a ) );
Insert Into( expr, Expr(Not( b )) );
Show( Name Expr( expr ) ); // Not(a) (!!)
回覆:JMP Expr() 怪異,有人能解釋嗎?你好,
儘管我不確定,但我想知道這種行為是否是因為片段“IF ( a )”不是格式良好的 JSL 表達式。 也就是說,函數 IF 採用 2 個參數,而不是 1 個。 JMP 無法知道「notAnIf( a )」是否是一個格式良好的表達式,因此也許聳聳肩並繼續(?)我的全部猜測。
事實上,以下內容按您的意圖工作似乎為這個想法添加了一些支持,但這並不能解釋為什麼@ben_ph的想法是有效的,因為它成功地在我丟失的地方插入了 REPLACE_ME 。
expr = Expr( If( a, . ) );
Substitute Into( expr, expr(.), expr( If( b, c ) ) );
Show( Name Expr( expr ) );

乾杯,
布雷迪
回覆:JMP Expr() 怪異,有人能解釋嗎?作為不使用字串的解決方法,您可以執行類似的操作
expr = Expr( If( a ) );
Insert Into( expr, Expr( REPLACE_ME ) );
Substitute Into( expr, Expr( REPLACE_ME ), Expr( If( b, c ) ) );
Name Expr( expr );
// If( a, If( b, c ) )
回覆:JMP Expr() 怪異,有人能解釋嗎?這是密切相關與如何將一個清單插入到另一個清單中。 對於你的問題,我現在懷疑內建函數名稱有一個特殊的例外,可以顯示這種行為。
expr = Expr( not an If( a ) );
是相同的
expr = Expr( NotAnIf( a ) );
將 NotAnIf(或不是 if)設為函數名稱 JMP 不會將其識別為內建函數。 在 { list } 範例中,{...} 與 List(...) 相同,且是內建函數名稱。
expr = Expr( sum( a ) );
插入( expr, Expr( sum( b, c ) ) );
Show( 名稱 Expr( expr ) );
/*:
名稱 Expr(expr) = Sum(a, b, c);
//:*/
expr = Expr( sum1( a ) );
插入( expr, Expr( sum1( b, c ) ) );
Show( 名稱 Expr( expr ) );
/*:
名稱 Expr(expr) = sum1(a, sum1(b, c));
我也不喜歡它。
@XanGregg
回覆:JMP Expr() 怪異,有人能解釋嗎?版本之間的一致性也很重要。 每種語言都有一些早期設計的缺陷。 有人(通常是開發人員和技術支援專家或銷售工程師)決定是否
修復的長期增益 - 修復成本 > 無所事事的成本
CostsOfFishing 確實很複雜,開發人員時間 + 測試時間 + 文件時間 + 短期技術支援時間 + 客戶對以前有效的 JSL 現在失敗的惱怒 + 錯失機會 + 使情況變得更糟的風險。
CostOfDoingNothing 也很複雜:需要多少技術支持,永遠到未來,將遇到這個問題的用戶數量,以及理解和解決這個問題有多難。 更多猜測。
這個論壇、願望清單論壇、您的 JMP 代表以及使用者群組會議都有助於引導您做出決定。 謝謝@hogi幫助駕駛!
@朱利安
回覆:JMP Expr() 怪異,有人能解釋嗎?這是一個有趣的問題。您可以創建自己的函數來執行插入操作,該函數按預期工作[我認為],對於除最後一種情況之外的所有情況@hogi 。對於這種情況,儘管函數傳回的結果與直接使用 Name Expr 呼叫該表達式時的結果相同,因此有人可能會認為這是「正確」的結果。
Names default to here(1);
// Make a new function to show each step of Insert Into:
New Insert Into = function( {exp, newarg, debug = 0 }, local({hd, ar, ne},
//Get the outermost function
hd = Head(exp);
if(debug, show(name expr( hd ) ) );
//Replace that function with a list so insert into works as expected
ar = substitute(name expr( exp ), name expr( hd ), {});
if(debug, show(name expr( ar ) ) );
//Now add the new argument
Insert Into( ar, name expr( newarg ) );
if(debug, show(name expr( ar ) ) );
//and put the orignial function back
ne = substitute(name expr( ar ), {}, name expr( hd ));
if(debug, show(name expr( ne ) ) );
Name expr( ne );
) );
// Test with the examples in the original post, note that they match:
Show( New Insert Into( Expr( If( a ) ), Expr( If( b, c ) ) ) ); // If(a, If(b, c))
Show( New Insert Into( Expr( Not an If( a ) ), Expr( If( b, c ) ) ) ); // Not an If(a, If(b, c))
// Additional examples from hogi post
Show( New Insert Into( Expr( If( a, x ) ), Expr( If( b, c ) ) ) ); // If(a, x, If(b, c))
Show( New Insert Into( Expr( If( a ) ), Expr( If( b ) ) ) ); // If(a, If
Show( New Insert Into( Expr( List( a ) ), Expr( List( b ) ) ) ); // List(a, b)
Show( New Insert Into( Expr( Graph Builder( a ) ), Expr( Graph Builder( b ) ) ) ); // Graph Builder(a, Graph Builder(b))
Show( New Insert Into( Expr( Head( a ) ), Expr( Head( b ) ) ) ); // Head(a, Head(b))
Show( New Insert Into( Expr( Not( a ) ), Expr( Not( b ) ) ) ); // !a
// The last one doesn't seem right but that it is actually being 'fixed' after as it is created:
Show( New Insert Into( Expr( Not( a ) ), Expr( Not( b ) ), debug = 1 ) ); // !a
// This is the same result as if you just call that directly, so I think this is the 'correct' result
Name Expr( Not(a, !b) ); // !a
// This function replaces all the Head expressions, which I think is okay, note this line:
// Name Expr(ar) = {a, {b, c}}
Show( New Insert Into( Expr( If( a, If( b, c ) ) ), Expr( If( d, e ) ), 1 ) ); // If(a, If(b, c), If(d, e))
這是沒有調試內容的相同功能:
New Insert Into = function( {exp, newarg }, local({hd, ar, ne},
hd = Head(exp);
ar = substitute(name expr( exp ), name expr( hd ), {});
Insert Into( ar, name expr( newarg ) );
ne = substitute(name expr( ar ), {}, name expr( hd ));
name expr( ne );
) );
回覆:JMP Expr() 怪異,有人能解釋嗎?這解決了 2x 相同類型表達式的問題。 是的。
但我擔心,它並不是通用的替代品插入正如人們所希望的那樣。
Show( New Insert Into( Expr( If( a )), Expr( List( b,c )) ) ); // If(a,b,c)
回覆:JMP Expr() 怪異,有人能解釋嗎?儘管如此,我的主要意圖是:
理解為什麼插入扁平化結構 - 這樣每當我將來使用該功能時,我可以確信它會做正確的事情。
對於 2 個列表,它看起來是一個有用的函數:它會自動產生一個扁平列表。
嗯,與圖形產生器中的自動範圍調整一樣有用 - 即:對於 93% 的情況它會有所幫助,對於其他情況...
熱圖 - 選項:固定刻度間距(聚合區域)
除了試圖「提供幫助」之外,還有其他更多的事情嗎?
對我來說新的是,它不僅僅是試圖幫助清單...
關於“解決方案”插入特殊情況是 2x 相同類型的表達式:
- 也許有一個隱藏的選項:不要壓平(0|1) ?
expr = Expr( If( a ) );
Insert Into( expr, Expr( REPLACE_ME ) );
Substitute Into( expr, Expr( REPLACE_ME ), Expr( If( b, c ) ) );
Name Expr( expr );
太棒了:)
注意:
@ih寫道:
....只有第一個實例應該被替換..
幾天前我遇到了類似的問題並提出了這個想法:表達式索引:讀寫存取。
它可以將 Jmp/JSL 中的表達式處理提升到一個新水平。 如果你覺得它有用,你可以投票給它...
[我添加了一條帶有這篇文章鏈接的評論。]
回覆:JMP Expr() 怪異,有人能解釋嗎?
@hogi寫道:
關於Insert Into的「解」以及 2x 相同類型表達式的特殊情況:
- 也許有一個隱藏選項: flatten(0|1) ?
看來不是那麼...
這裡希望得到這樣一個選項: Insert Into: Flatten(0|1)