More Related Content
Similar to “Tasks” in NetLogo 5.0beta1 (20)
“Tasks” in NetLogo 5.0beta1
- 2. What are tasks? chunks of code to be run once,run repeatedly, passed around, stored in variables, etc.
- 12. Implicit task syntax map [? * ?] [1 2 3] => [1 4 9] filter [? mod 2 = 0] [1 2 3 4] => [2 4] foreach sort turtles [ print ? ]
- 13. Explicit task syntax set next-task task [ fd 1 ] set coloring task [ ifelse-value (wealth > 100) [ red ] [ blue ] ]
- 14. Disambiguation of task type command or reporter?look at first token after the opening bracket (skipping left parens)
- 17. Running tasks (variadic) let printer task [ print ?1 + ?2 ] (run print 2 3) => 5 let square task [? * ?] print (runresult square 5) => 25
- 18. Concise task syntax task die short for task [ die ] task fd short for task [ fd ? ] task + short for task [?1 + ?2]
- 19. Concise + implicit syntax map abs [1 -2 3 -4] => [1 2 3 4] reduce + [1 2 3 4] => 10 filter is-number? [1 “x” 3] => [1 3]
- 25. Current agent not closed over globals [g] ask turtle 0 [ set g task [ print who ] ] ask turtle 1 [ run g ] => 1
- 26. Nonlocal exits stop and report refer to dynamically enclosing procedure, not enclosing task(backwards compatible)
- 29. Use tasks, not strings! but, still need strings with run/runresult for running code entered by end user
- 32. Wouldn’t it be cool if?:automatic updating set label task [energy] set color task [ ifelse-value (wealth < 100) [red] [blue] ]