foreach - Netlogo - expected constant error -
i have line of code:
set ssb sum [foreach [foglie [ipotetico? = false]] [((([media] of self ) - media-tot ) ^ 2) * ([larg] of self * [altez] of self)]]
- foglie agentlist;
- media-tot global variable
i cannot figure out why gives me error:
expected constant
i found following loophole looks me not elegant , maybe slower:
set ssb 0 ask foglie [ipotetico? = false] [ set ssb (ssb + (( [media] of self - media-tot) ^ 2) * ([larg] of self * [altez] of self)) ]
- what think?
- how can make first code work?
- is second code equivalent?
a question include minimal example of problem. in case, in first attempt above, looks not understand difference between agentsets , lists, nor use of foreach
. need read this.
sum
requires list input- to make list bracket notation, need include constants; otherwise, use
list
- putting agentset in brackets not produce list, above reason, if used
list
list containing agentset element, not list of agents foreach
not return list (butmap
does)
assuming media
, larg
, , altez
foglie attributes , media-tot
global, have done following:
sum [(media - media-tot) ^ 2 * (larg * altez)] of (foglie [ipotetico? = false])