如何有选择地评估 New Script() 中的变量,同时保留 Expr() 以进行延迟评估?我正在使用创建数据表脚本New Script()稍后用户点击时需要进行评估。我需要在脚本创建时替换一些变量(例如文件路径),同时保留Expr()仅当脚本实际运行时才应评估调用。
file_path = "C:\MyData\slopes.jmp";
dt << New Script("Plot Slopes",
dt_slopes = Open( file_path );
slope_array = dt_slopes:slope << Get Values;
nw = New Window( "Slope Plots",
gb = Graph Box()
);
framebox = gb[Frame Box(1)];
For Each( {slope}, slope_array,
Eval( Eval Expr(
framebox << Add Graphics Script(
Y Function( Expr(slope) * x, x );
);
));
);
);
问题: I need file_path to be evaluated and inserted as a literal string when creating the script, but the Expr(slope) inside the For Each loop must remain unevaluated until the script runs (when the user clicks it).
If I wrap everything in Eval(Eval Expr()) to substitute file_path, it also evaluates Expr(slope)prematurely, causing an error since slope doesn't exist yet.
在存储的数据表脚本中,选择性地评估某些变量同时保留其他变量以供延迟评估的正确方法是什么?
自动化和脚本回复:如何选择性地评估 New Script() 中的变量,同时保留 Expr() 以进行延迟评估?一种选择是将一些 Expr(Name Expr()) 添加到您的代码中
Names Default To Here(1);
file_path = "C:\MyData\slopes.jmp";
Eval(EvalExpr(
dt << New Script(
"Plot Slopes",
dt_slopes = Open(Expr(file_path));
slope_array = dt_slopes:slope << Get Values;
nw = New Window("Slope Plots", gb = Graph Box());
framebox = gb[Frame Box(1)];
Expr(Name Expr(For Each({slope}, slope_array,
Eval(Eval Expr(framebox << Add Graphics Script(Y Function(Expr(slope) * x, x))))
)));
);
));
当你只运行 EvalExpr 部分时,你将得到以下脚本
dt << New Script(
"Plot Slopes",
dt_slopes = Open("C:\MyData\slopes.jmp");
slope_array = dt_slopes:slope << Get Values;
nw = New Window("Slope Plots", gb = Graph Box());
framebox = gb[Frame Box(1)];
For Each({slope}, slope_array,
Eval(
Eval Expr(
framebox << Add Graphics Script(Y Function(Expr(slope) * x, x))
)
)
);
)

回复:如何选择性地评估 New Script() 中的变量,同时保留 Expr() 以进行延迟评估?不错的技巧:
expr(名称 expr())作为保护()的同义词
也许在这里投票:
expr() 的两种含义对应两种函数