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 (but map does)

assuming media, larg, , altez foglie attributes , media-tot global, have done following:

sum [(media - media-tot) ^ 2 * (larg * altez)] of (foglie [ipotetico? = false]) 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -