규모가 큰 대본을 작업하면서 표정과 관련된 몇 가지 흥미로운 현상을 발견했습니다.
다음의 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 />그게 제 문제를 해결했습니다. 하지만 제 스크립트의 구조를 감안하면, 실제로는 다른 함수, 예를 들어 f3에서 함수 f2를 호출해야 했습니다.
<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를 삼중 중첩 표현식으로 수정하면 문제가 해결된다는 것을 알았습니다. 즉, 그래프를 표현식으로 저장하면서 평가는 억제합니다.
<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. 그 링크도 매우 도움이 됩니다.