Reputation: 789
I have this line of code:
set SSB sum [foreach [foglie with [ipotetico? = false]] [((([media] of self ) - media-tot ) ^ 2) * ([larg] of self * [altez] of self)]]
I cannot figure out why it gives me the error:
expected constant
I found the following loophole but it looks to me not elegant and maybe even slower:
set SSB 0
ask foglie with [ipotetico? = false] [ set SSB (SSB + (( [media] of self - media-tot) ^ 2) * ([larg] of self * [altez] of self)) ]
Upvotes: 1
Views: 362
Reputation: 9620
A good question will include a minimal example of the problem. In this case, in your first attempt above, it looks like you do not understand the difference between agentsets and lists, nor the use of foreach
. So you need to read about this.
sum
requires a list as inputlist
list
you would get a list containing the agentset as an element, not a list of the agentsforeach
does not return a list (but map
does)Assuming media
, larg
, and altez
are foglie attributes and media-tot
is a global, you could have done the following:
sum [(media - media-tot) ^ 2 * (larg * altez)] of (foglie with [ipotetico? = false])
Upvotes: 3