构建NetLogo列表时出现“期望值为常量”错误

时间:2014-06-09 23:06:31

标签: netlogo fractals

我目前正致力于使用IFS构造scheme在NetLogo中创建Levy C-Curve的图形表示。我找到了两个函数来描述如何迭代地映射两只乌龟的位置,并且在数千次迭代之后应该产生所需的曲线。到目前为止,这是我的代码:

 ;;;;;; some useful complex operations

 ; to take re(z) of a complex number a + bi inputed as the list of coordinates [a b]

 to-report re [z]
 report first z
 end


 ; to take im(z)

 to-report im [z]
 report last z
 end

 ; to multiply two complex numbers

 to-report complex_mul [z1 z2]
 report list (re z1 * re z2 - im z1 * im z2) 
             (re z1 * im z2 + im z1 * re z2) 
 end


 ; to add complex numbers

 to-report complex_add [z1 z2]
 report list (re z1 + re z2)
             (im z1 + im z2)
 end


 ; to dilate complex numbers by a scalar fraction

 to-report complex/real [z1 real]
 report list (re z1 / real)
             (im z1 / real)
 end 

 ; to initialize

 to setup
 ca
 setup-turtles
 reset-ticks
 end


 ; create 2 turtles located at the initial set of points {0, 1}

 to setup-turtles
 crt 2
 ask turtle 0 [ setxy 0 0]
 ask turtle 1 [ setxy 1 0]
 ask turtles [ pd]
 end


 ; to create the first function to transform the turtle's location

 to-report nextz_1 [z] 
 report complex/real (complex_mul [1 -1] z) 2
 end 


 ; to create the second function to transform the turtle's location

 to-report nextz_2 [z]
 report complex_add [1 0] 
                    (complex/real (complex_mul [1 1] 
                                                (complex_add z [-1 0]))
                                   2) 
 end

 ; finally we are creating the Levy Curve

 to levy
  ask turtles [ run one-of (list task setxy re (nextz_1 [xcor ycor]) im (nextz_1 [xcor ycor])
                                 task setxy re (nextz_2 [xcor ycor]) im (nextz_2 [xcor ycor])
                               )
           ]

 end

然而,我在“levy”代码块中收到一条错误消息,我在其中调用re(nextz_1 [xcor ycor])等,说NetLogo期望代替xcor和ycor的常数值。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

http://ccl.northwestern.edu/netlogo/docs/faq.html#listexpectedconstant,NetLogo常见问题解答说:

  

如果一个列表只包含常量,你只需在其周围加上方括号即可写下来,如[1 2 3]

     

如果希望列表包含可能在运行时变化的项目,则无法直接写下列表。相反,您使用list原语构建它。

您实际上已在代码的其他位置使用此权限,但在levy过程中,您需要替换例如[xcor ycor]list xcor ycor