Netlogo 使用run with匿名过程

Netlogo 使用run with匿名过程,netlogo,Netlogo,我是netlogo的新手,在理解与匿名过程运行相关的性能问题时遇到困难 我主要关心的是,在匿名过程中使用run或runresult是否会导致性能下降,或者这是否与仅在字符串输入中使用run/runresult有关 谢谢 一些代码: 我的理解是,您可以通过以下两种不同的方式实现相同的结果(可能还有更多,但正如我所说,我只是从netlogo开始,所以我可以想出以下两种方式): vs 有什么区别 此外,在文档中还指出,类似于runresult(word“helper”a-list)的东西原则上应该可以

我是netlogo的新手,在理解与匿名过程运行相关的性能问题时遇到困难

我主要关心的是,在匿名过程中使用run或runresult是否会导致性能下降,或者这是否与仅在字符串输入中使用run/runresult有关

谢谢

一些代码: 我的理解是,您可以通过以下两种不同的方式实现相同的结果(可能还有更多,但正如我所说,我只是从netlogo开始,所以我可以想出以下两种方式):

vs

有什么区别

此外,在文档中还指出,类似于
runresult(word“helper”a-list)
的东西原则上应该可以工作,但我不能让它运行(我会遇到运行时错误)


这最后一行不是应该正确计算吗?我做错了什么?另外,在什么意义上运行结果可以“运行”字符串?

执行匿名过程比运行字符串快得多。问题是字符串需要转换为一些可执行代码,然后执行

如果您比较用户定义函数和匿名过程,则情况就不同了,这取决于用例。例如,如果您有一个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的字符串命令不能设置/读取局部变量。您的助手是一个局部变量

请参阅文档:

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的运行允许字符串、匿名过程或函数。下面是一个运行字符串创建5个海龟的示例。运行“crt 5”很抱歉,但我不明白为什么
runresult(单词“helper”a-list)
没有在我的报告中运行它们都会为我在它们上尝试过的任何有效输入生成相同的输出;正确,
runresult(单词“sum”[1 2 3])
按预期工作;为什么
runresult(单词“helper”a-list)
计算不正确?
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.