对函数的返回值进行索引今天的挑战:
f=Function({}, {1,2,3});
tmp=f();
y=tmp[1]; // works
x=f()[1] // doesn't work
理解这个问题对理解 JSL 的工作原理非常有帮助 
自动化和脚本编写回复:对函数的返回值进行索引逆问题:
names default to here(1);
x=1;
Eval(x=1); // "does the same"
x= Expr(hello);
Eval(x= Expr(hello)); // fails
回复:对函数的返回值进行索引Head 是否对其论点进行评估?
关于assign 函数,它会评估其参数吗?
1. 参数:否
2. 参数:是
如果需要“手动”计算表达式的值(在从结果中取出第一个元素之前),请使用 Eval() 函数:
x=f()[1] // doesn't work
x=Eval(f())[1] // works
关于胶水:
是否需要参数:是
……以及 Eval:
是的当然!
除此之外,在对参数进行第一次求值之后,还会对返回值进行一次额外的求值*)。
Eval(print(1);x= Expr(hello);print(x); Expr(print(2)));
正确地将x=Expr(hello)赋值给变量,并打印出:

*) -> 链接/文档/社区?
回复:对函数的返回值进行索引
If you need to evaluate an expression "manually" [
前 taking the fist item from the result], use Eval():
</CODE>
<HR />
</BLOCKQUOTE>
<P>我认为这样做会生成难以阅读的代码,不应该使用,直接返回值并使用它就好。如果你知道只需要某个特定的索引(<STRONG>并且知道有多少个这样的索引</STRONG>),你可以使用列表,然后“丢弃”其余的索引。</P>
<BR />
<PRE><CODE class=" language-jsl">Names Default To Here(1);
return_list = Function({}, {Default Local}, return({1,2,3}));
{res, _, _} = return_list();
show(res, _);
正确分配 x=Expr(hello) 以及印刷品:
我认为这应该会导致错误(目前我认为这是一种意料之外的行为)。我猜测这是因为 Glue 的工作方式(它返回最后一个结果,然后对其进行求值)。
Names Default To Here(1);
Eval(
x = Expr(hello);
Print(x);
);<BR />// Eval(Glue(Assign(x, Expr(hello)), Print(x)));
vs (名称未解析:访问或评估“hello”时出现“hello”,hello/*###*/ )
Names Default To Here(1);
Eval(
x = Expr(hello);
);<BR />// Eval(Assign(x, Expr(hello)));
我觉得如果像这样使用 Eval,就应该总是发生这种情况(尝试计算 Expr() 的值 -> 计算失败 -> 抛出错误)。 @EvanMcCorkle
查看更多......
Names Default To Here(1);
a = 1;
Try(
Eval(
x = Expr(hello);
y = Expr(a);
);
,
Write("\!NFirst Example: ", exception_msg);
);
Try(
Eval(
y = Expr(a);
x = Expr(hello);
);
,
Write("\!Second Example: ", exception_msg);
);
如果您只想将“hello”名称存储在变量中,请使用 NameExpr() 函数。
Names Default To Here(1);
x = NameExpr(hello);
脚本编写指南 > 编程方法 > 高级表达式、宏和列表虽然有一些错误,但总体来说是正确的,值得一读。
回复:对函数的返回值进行索引感谢您提供的补充示例和您的想法。
回复:对函数的返回值进行索引啊,当我们考虑一个带有参数的函数时,事情就变得清晰多了:
g=Function({x}, {1,2,3});
x=g()[1] // doesn't work (uses the function itself and takes the first element)
x=g("")[1] // works -> 1 (runs the function - then takes the first element)