I'm considering implementing argmax using (map and reduce) and iterating.
Here's my implementation using map and reduce:
 to-report argmax1 [arguments f]
   if length arguments = 0 [ show "incorrect length of arguments" report nobody]
   report first reduce [ ifelse-value ((last ?1) > (last ?2)) [?1] [?2]] map [(list ? (runresult f ?))] arguments
 end
Here's my implementation using iterations.
 to-report argmax2 [arguments f]
   if length arguments = 0 [ show "incorrect length of arguments" report nobody]
   let max-argument first arguments 
   let max-evaluation runresult f max-argument
   foreach arguments 
   [
     let current-evaluation runresult f ?
     if current-evaluation > max-evaluation
     [
      set max-argument ?
      set max-evaluation current-evaluation 
     ]
   ]
   report max-argument
 end
My question is: Is there any benefits from using the built-in functions? In my map/reduce code, I iterate over the list twice compared with iterating over it once when not using map/reduce. In python, map/reduce would be a speed-up since it compiles to C rather than python byte code. Is there an equivalent for netlogo?
Thoughts?
 
    