Search code examples
dictionarynetlogoprimitive

Netlogo v6.01: converting map function to anonymous procedures


I'm upgrading a Netlogo model from v5.3.1 to v6.01. In the model, I have a series of lists that I combine/manipulate using the map primitive. I've tried to update the code using the new anonymous procedures, but I can't quite figure it out. I was using the ? syntax, but ? is no longer defined.

Original code:

Parameters:

C, WC-Alpha, A, and Z are all lists

alpha is a constant

set C-alpha map [? ^ (- alpha)] C ;creates a vector of C^-alpha

set R map [? * (A * Z)] WC-alpha ;creates R vector

Best, Todd


Solution

  • Have you had a look at the dictionary entry for map? It shows the new syntax, where essentially you define the variable to be used by map. For example, yours might look like:

    set C-alpha map [ i -> i ^ (- alpha) ] C
    

    where you explicitly state that you will be using i as the variable for the mapping operation. This allows for more readable code in map and other anonymous procedures.