大きなスクリプトに取り組んでいるときに、表現に関する興味深い動作に気づきました。
次の jsl コードを検討してください。
<FONT color="#339966">// Create a namespace for cleanliness</FONT>
ns = New Namespace("ns");
<FONT color="#339966">// Make an example data table dt</FONT>
ns:dt = <FONT color="#3366FF">New Table</FONT>("window",
<FONT color="#3366FF">New Column</FONT>("a", set values([1,2,3])),
<FONT color="#3366FF">New Column</FONT>("b", set values([1,4,9]))
);
<FONT color="#339966">// 1. Make an expression gr_exp1 containing the graph builder instructions</FONT>
ns:gr_exp1 = <FONT color="#3366FF">expr</FONT>(ns:gr = ns:dt << <FONT color="#0000FF">Graph Builder</FONT>(
Show Control Panel( 0 ),
Variables( X( :a ), Y( :p</img> ) ),
Elements( Points( X, Y, Legend( 8 ) ), Smoother( X, Y, Legend( 9 ) ) ));
);<BR /><FONT color="#339966">// Running the expression will build the graph (as expected)
<FONT color="#000000">ns:gr_exp1;</FONT><BR />
// 2. Make a function f1 that saves the graph builder instructions into an expression gr_exp2</FONT>
ns:f1 = <FONT color="#3366FF">function</FONT>({},{Default Local},
ns:gr_exp2 = <FONT color="#3366FF">expr</FONT>(ns:gr = ns:dt << <FONT color="#0000FF">Graph Builder</FONT>(
Show Control Panel( 0 ),
Variables( X( :a ), Y( :p</img> ) ),
Elements( Points( X, Y, Legend( 8 ) ), Smoother( X, Y, Legend( 9 ) ) ));
);
);
<FONT color="#339966">// When one runs the function, the graph will be displayed, though only saving the <BR />// expression into a variable is desired.</FONT>
ns:f1;このスクリプトではグラフを式として保存し (後で評価する) たかっただけなので、ポップアップは表示したくありませんでした。試行錯誤した結果、式を別の式にネストすると問題が解決することに気付きました。
ns:f2 = <FONT color="#3366FF">function</FONT>({},{Default Local},
ns:gr_exp2 = <FONT color="#3366FF">expr</FONT>(<FONT color="#3366FF">expr</FONT>(ns:gr = ns:dt << Graph Builder(
Show Control Panel( 0 ),
Variables( X( :a ), Y( :p</img> ) ),
Elements( Points( X, Y, Legend( 8 ) ), Smoother( X, Y, Legend( 9 ) ) ));
));
);<BR /><FONT color="#339966">// Now no graph is displayed when running the function, and the expression is saved!</FONT><BR />ns:f2;<BR />これで問題は解決しました。しかし、スクリプトの構造を考えると、実際には関数 f2 を別の関数、たとえば f3 から呼び出す必要がありました。
<FONT color="#339966">// 4. Now make a function f3 that calls f2 (with the idea of simply saving an expression)</FONT>
ns:f3 = <FONT color="#3366FF">function</FONT>({},{Default Local},
ns:f2;
);
<FONT color="#339966">// Running the script will produce a graph again...</FONT>
ns:f3;その後、関数 f2 を変更して 3 重ネストされた式にすると問題が解決することに気付きました。グラフを式として保存し、その評価を抑制します。
<FONT color="#339966">// This can be solved by modifying f2</FONT>
ns:f2 = <FONT color="#3366FF">function</FONT>({},{Default Local},
ns:gr_exp2 = <FONT color="#3366FF">expr</FONT>(<FONT color="#3366FF">expr</FONT>(<FONT color="#3366FF">expr</FONT>(ns:gr = ns:dt << Graph Builder(
Show Control Panel( 0 ),
Variables( X( :a ), Y( :p</img> ) ),
Elements( Points( X, Y, Legend( 8 ) ), Smoother( X, Y, Legend( 9 ) ) ));
)));
);
<FONT color="#339966">// Running f3 now acts as desired (saves expression and suppresses evaluation of graph)</FONT>
ns:f3;私はこの問題をなんとか乗り越えましたが、私の疑問は次のとおりです。
呼び出し時に式を評価せずに式を変数に保存する関数を (正しく) 作成するにはどうすればよいですか?
私は JMP Pro 18.0 を使用しています。ご助言やコメントをいただければ幸いです。
こんにちは@ThomasB 、
関数の最後の式が戻り値として使用されることに注意してください。
式を「返す」ことなく割り当てるだけの場合は、ダミーの戻り値を追加してください。
ns:f1 = function({},{Default Local},
ns:gr_exp2 = expr(ns:gr = ns:dt << Graph Builder(
Show Control Panel( 0 ),
Variables( X( :a ), Y( ) ),
Elements( Points( X, Y, Legend( 8 ) ), Smoother( X, Y, Legend( 9 ) ) ));
);
1;
);または
ns:f1 = function({},{Default Local},
ns:gr_exp2 = expr(ns:gr = ns:dt << Graph Builder(
Show Control Panel( 0 ),
Variables( X( :a ), Y( ) ),
Elements( Points( X, Y, Legend( 8 ) ), Smoother( X, Y, Legend( 9 ) ) ));
);
return(1);
);
Jarmoさん、返信とリンクをありがとうございます。とても役に立ちました。