我是新的网络标志,我有困难的理解性能问题与使用运行与匿名程序。
我主要关心的是,在匿名过程中使用run或runresult是否会导致性能上的损失,或者如果这是与只对字符串输入使用run/run结果有关的。
谢谢
一些代码:
我的理解是,您可以通过以下两种不同的方法获得相同的结果(可能还有更多的方法,但就像我刚才说的,我刚刚开始使用网络徽标,所以这些都是我可以想出来的):
to-report list-made-up-of-empty-lists? [ a-list ]
let helper [ [ arg ] -> ( reduce and ( map empty? arg ) )]
report ( map helper ( list a-list ) )
endvs
to-report list-made-up-of-empty-lists? [ a-list ]
let helper [ [ arg ] -> ( reduce and ( map empty? arg ) )]
report ( list ( runresult helper a-list ) )
end有什么关系呢?
此外,在文档中指出,像runresult ( word "helper " a-list )这样的东西原则上应该工作,但我不能让它运行(我得到运行时错误)。
这最后一行不应该正确评估吗?我做错了什么?另外,从什么意义上说,runresult可以“运行”字符串?
发布于 2019-07-30 13:28:51
执行匿名过程比运行字符串要快得多。问题是,该字符串需要转换为一些可执行代码,然后执行。
如果您将用户定义的函数与匿名过程进行比较,则情况就不同了,并且取决于用例。例如,如果您有一个For循环,并且在循环中创建了一个匿名函数,而不是在循环之外创建它一次(或者预先定义它),那么您可能会看到一个缓慢的过程。
Netlogo的运行文档:
run command
(run command input1 ...)
run string
runresult reporter
(runresult reporter input1 ...)
runresult string
The run form expects the name of a command, an anonymous command, or a string containing commands. This agent then runs them.
The runresult form expects the name of a reporter, an anonymous reporter, or a string containing a reporter. This agent runs it and reports the result.此外,代码不能处理字符串的原因是以下原因:Netlogo的string命令无法设置/读取局部变量。您的助手是一个局部变量。
见文件:
匿名过程可以自由读取和/或设置局部变量和过程输入。尝试对字符串进行同样的操作可能有效,也可能不起作用,不应依赖于此。
https://stackoverflow.com/questions/57267570
复制相似问题