NetLogo:TO-REPORT 的含义解释给傻瓜听?
NetLogo: the meaning of TO-REPORT explained for dummies?
我无法理解 to-report
和 report
在 NetLogo 中的作用,即使它看起来很有用,我也找不到用 "human style" 语言编写的帮助.
在 NetLogo 词典 http://ccl.northwestern.edu/netlogo/docs/dictionary.html#report 中,我可以找到 to-report
的定义:
to-report procedure-name
to-report procedure-name [input1 ...]
Used to begin a reporter procedure.
The body of the procedure should use report to report a value for the procedure. See report.
以及 report
:
report value
Immediately exits from the current to-report procedure and reports value as the result of that procedure. report and to-report are always used in conjunction with each other. See to-report for a discussion of how to use them.
所以,似乎 to-report
和 report
计算了一些值并报告了它。
因此,当我尝试添加
to-report average [a b c]
report (a + b + c) / 2
end
到我的代码,然后在我的代码 p.e.:
的某处使用 average
变量
to go
...
print average
tick
end
我有一个错误:AVERAGE expected 3 inputs
。当我尝试在 globals [a b c]
中创建变量 [a b c] 时,出现错误 There is already a global variable called A
。
如果我在 to-report
过程中定义我的变量 [a b c]
:
to-report average [a b c]
set a 1
set b 2
set c 3
report (a + b + c) / 2
end
我的错误又是AVERAGE expected 3 inputs
。
因此,如何简单地测试to-report程序的有用性?以及在我的代码中正确放置它的位置以查看它真正在做什么? 来自 Urban Suite - Economic Disparity (http://ccl.northwestern.edu/netlogo/models/UrbanSuite-EconomicDisparity) 我看到 to-report 用于计算与每个补丁:
to-report patch-utility-for-poor
report ( ( 1 / (sddist / 100 + 0.1) ) ^ ( 1 - poor-price-priority ) ) * ( ( 1 / price ) ^ ( 1 + poor-price-priority ) )
end
但是这个报告的值没有直接定义为补丁变量,这增加了我的困惑...
谢谢!
一个函数可以接受一些输入(通常是一个或多个变量或值)和 return 一些输出(通常是单个值)。您可以在函数头中使用 to-report 指定函数 return 的值,并报告 return 的实际值。
您的错误是由于您从未将参数传递给平均函数
to go
...
print average
tick
end
应该是
to go
...
print average 5 2 3 ;;a = 5, b = 2, c =3
tick
end
在你的 average 函数中,你不应该重新分配 a、b 和 c 的值。
只要您想 return 函数的结果,就应该使用报告。
我无法理解 to-report
和 report
在 NetLogo 中的作用,即使它看起来很有用,我也找不到用 "human style" 语言编写的帮助.
在 NetLogo 词典 http://ccl.northwestern.edu/netlogo/docs/dictionary.html#report 中,我可以找到 to-report
的定义:
to-report procedure-name
to-report procedure-name [input1 ...]
Used to begin a reporter procedure.
The body of the procedure should use report to report a value for the procedure. See report.
以及 report
:
report value
Immediately exits from the current to-report procedure and reports value as the result of that procedure. report and to-report are always used in conjunction with each other. See to-report for a discussion of how to use them.
所以,似乎 to-report
和 report
计算了一些值并报告了它。
因此,当我尝试添加
to-report average [a b c]
report (a + b + c) / 2
end
到我的代码,然后在我的代码 p.e.:
的某处使用average
变量
to go
...
print average
tick
end
我有一个错误:AVERAGE expected 3 inputs
。当我尝试在 globals [a b c]
中创建变量 [a b c] 时,出现错误 There is already a global variable called A
。
如果我在 to-report
过程中定义我的变量 [a b c]
:
to-report average [a b c]
set a 1
set b 2
set c 3
report (a + b + c) / 2
end
我的错误又是AVERAGE expected 3 inputs
。
因此,如何简单地测试to-report程序的有用性?以及在我的代码中正确放置它的位置以查看它真正在做什么? 来自 Urban Suite - Economic Disparity (http://ccl.northwestern.edu/netlogo/models/UrbanSuite-EconomicDisparity) 我看到 to-report 用于计算与每个补丁:
to-report patch-utility-for-poor
report ( ( 1 / (sddist / 100 + 0.1) ) ^ ( 1 - poor-price-priority ) ) * ( ( 1 / price ) ^ ( 1 + poor-price-priority ) )
end
但是这个报告的值没有直接定义为补丁变量,这增加了我的困惑...
谢谢!
一个函数可以接受一些输入(通常是一个或多个变量或值)和 return 一些输出(通常是单个值)。您可以在函数头中使用 to-report 指定函数 return 的值,并报告 return 的实际值。
您的错误是由于您从未将参数传递给平均函数
to go
...
print average
tick
end
应该是
to go
...
print average 5 2 3 ;;a = 5, b = 2, c =3
tick
end
在你的 average 函数中,你不应该重新分配 a、b 和 c 的值。
只要您想 return 函数的结果,就应该使用报告。