将 Expr() 对象作为未评估的 Expr() 对象插入到另一个脚本中以供稍后使用?在将解析表达式的内容而不是变量名插入新脚本中,添加到@jthi的答案,如何将 Expr() 对象作为未评估的 Expr() 对象插入到另一个脚本中以供稍后使用?
我正在使用 JMP 18.1.2
Names Default To Here( 1 );
dt = New Table( "My Table" );
e1 = Expr(
Print( "Run some code." )
);
e2 = Expr(
e1;
Print( "Run some other code." );
);
e3 = Eval Expr(
Expr( Name Expr( e1 ) ); // Define, but do not evaluate e1 here.
Expr( Name Expr( e2 ) ); // Evaluate e1 here.
);
Show( e3 );
Eval( Eval Expr( dt << New Script( "Test", Expr( Name Expr( e3 ) ) ) ) );
自动化和脚本视窗回复:将 Expr() 对象作为未评估的 Expr() 对象插入到另一个脚本中以供稍后使用?JMP中的一个巧妙技巧:
您可以按下数字键盘上的Enter键来运行一行代码。
这对于调试非常有帮助。
另一个技巧:
右键单击脚本窗口并激活:

最后一招:
在 Eval( ) 内部标记 Eval Expr(... )并“运行”它来检查表达式是否符合您的预期:

这表明你在哪里写
// Evaluate e1 here.
名称表达式仅采用存储在变量中的表达式。 它不对其进行求值。 e1保持为e1 。
编辑:
但也许这就是你想要实现的?没有问题 - 只是评论?
JSL 脚本会将“e1”写入表格脚本。
当用户运行表脚本时,JMP 将尝试评估 e1。
这意味着:您必须在数据表上下文中定义 e1,否则您将收到错误消息:

[e1 只是在脚本的此处命名空间内定义]
回复:将 Expr() 对象作为未评估的 Expr() 对象插入到另一个脚本中以供稍后使用?我不太清楚你要做什么,因为 e1 已经在第 5 行定义了。你希望在 e3 里面放什么?像这样
e1 = Expr(Print("Code"));
e1; //e2
Print("Code2"); //e2
或者
e1 = Expr(Print("Code"));
Print("Code");
Print("Code2"); //e2回复:将 Expr() 对象作为未评估的 Expr() 对象插入到另一个脚本中以供稍后使用?感谢@hogi和@jthi提供的意见。我能够通过使用函数来实现我想要的结果。
Names Default To Here( 1 );
dt = New Table( "My Table" );
e1 = Expr(
f1 = Function( {},
{Default Local},
Print( "Run some code." )
)
);
e2 = Expr(
f1();
Print( "Run some other code." );
);
e3 = Expr(
f1();
Print( "Run even more code." );
);
e4 = Eval Expr(
Expr( Name Expr( e1 ) ); // Define, but do not evaluate e1 here.
Expr( Name Expr( e2 ) ); // Evaluate e1 here.
Expr( Name Expr( e3 ) ); // Evaluate e1 here.
);
Eval( Eval Expr( dt << New Script( "Test", Expr( Name Expr( e4 ) ) ) ) );回复:将 Expr() 对象作为未评估的 Expr() 对象插入到另一个脚本中以供稍后使用?您还可以将其包装到额外的 Expr 中
Names Default To Here(1);
dt = New Table("My Table");
e0 = Expr(e1 = Expr(Print("Run some code.")));
e2 = Expr(
e1;
Print("Run some other code.");
);
e3 = Eval Expr(
Expr(Name Expr(e0)); // Define, but do not evaluate e1 here.
Expr(Name Expr(e2)); // Evaluate e1 here.
);
Show(e3);
Eval(Eval Expr(dt << New Script("Test", Expr(Name Expr(e3)))));

回复:将 Expr() 对象作为未评估的 Expr() 对象插入到另一个脚本中以供稍后使用?非常聪明!谢谢。