SlideShare a Scribd company logo
1 of 34
“Tasks” in NetLogo 5.0beta1 March 21, 2011
What are tasks? chunks of code to be run once,run repeatedly, passed around, stored in variables, etc.
Known elsewhere as closures first-class functions lambda
Tasks in NetLogo 5.0 2 new data types 3 new primitives 8 primitives altered
2 new data types Command tasks Reporter tasks
3 new primitives task is-command-task? is-reporter-task?
6 altered primitives map, filter, reduce,n-values, sort-by foreach
2 more altered primitives run runresult
NOT altered (for now) ifelse, while, repeat, loop, ...
NOT altered (for now) ask, of, with, all?, ...
Backward compatible syntax square brackets inputs: ?1 (aka ?), ?2, ?3, ...
Implicit task syntax map [? * ?] [1 2 3] => [1 4 9] filter [? mod 2 = 0] [1 2 3 4] => [2 4] foreach sort turtles [ print ? ]
Explicit task syntax set next-task task [ fd 1 ] set coloring task [ ifelse-value (wealth > 100) [ red ] [ blue ] ]
Disambiguation of task type command or reporter?look at first token after the opening bracket (skipping left parens)
No tasks “escape” unless you use the explicit syntax
Running tasks run task [ print 5 ] => 5 print runresult task [5] => 5
Running tasks (variadic) let printer task [ print ?1 + ?2 ] (run print 2 3) => 5 let square task [? * ?] print (runresult square 5) => 25
Concise task syntax task die  short for     task [ die ] task fd   short for     task [ fd ? ] task +    short for    task [?1 + ?2]
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]
Extra inputs are ignored (runresult task [? * 2] 1 10 100)=> 2
Tasks are closures close over procedure inputs close over local variables
Closing over procedure inputs to-report printer [x]  report task [ print x ] end run printer 5 => 5
Closing over local variables let x 5 let y task [ print x ] run y => 5
Close over bindings, not values let x 5 let y task [x] set x 10 print runresult y => 10
Current agent not closed over globals [g] ask turtle 0 [ set g task [ print who ] ] ask turtle 1 [ run g ] => 1
Nonlocal exits stop and report refer to dynamically enclosing procedure, not enclosing task(backwards compatible)
It’s fast 100x faster than compiling a string
Models using explicit tasks State Machine Example Termites 3D (afraid that’s all at the moment)
Use tasks, not strings! but, still need strings with run/runresult for running code entered by end user
Possible future work:named inputs [x => x * x] (or something like that?not sure yet)
Possible future work:complex reporter tasks task [  let x ...  ...  report ... ]
Wouldn’t it be cool if?:automatic updating set label task [energy] set color task [  ifelse-value (wealth < 100)    [red] [blue] ]
Wouldn’t it be cool if?:scheduling in-ticks 5 task [ fd 1 ]
Questions? http://groups.yahoo.com/group/netlogo-users

More Related Content

What's hot

งานPop pornapa
งานPop pornapaงานPop pornapa
งานPop pornapa
Pw Mlp
 
Composition Of Functions
Composition Of FunctionsComposition Of Functions
Composition Of Functions
sjwong
 
L3 functions operations
L3 functions operationsL3 functions operations
L3 functions operations
James Tagara
 

What's hot (20)

Scheduling in Linux and Web Servers
Scheduling in Linux and Web ServersScheduling in Linux and Web Servers
Scheduling in Linux and Web Servers
 
Understanding the nodejs event loop
Understanding the nodejs event loopUnderstanding the nodejs event loop
Understanding the nodejs event loop
 
Synapse india dotnet development overloading operater part 4
Synapse india dotnet development overloading operater part 4Synapse india dotnet development overloading operater part 4
Synapse india dotnet development overloading operater part 4
 
Soft Heaps
Soft HeapsSoft Heaps
Soft Heaps
 
Pivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro BignyakPivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro Bignyak
 
Java 8 - functional features
Java 8 - functional featuresJava 8 - functional features
Java 8 - functional features
 
Functional Programming with Clojure
Functional Programming with ClojureFunctional Programming with Clojure
Functional Programming with Clojure
 
Result and screen shots
Result and screen shotsResult and screen shots
Result and screen shots
 
งานPop pornapa
งานPop pornapaงานPop pornapa
งานPop pornapa
 
Composition Of Functions
Composition Of FunctionsComposition Of Functions
Composition Of Functions
 
Get Reactive: Microservices, Programming, and Systems
Get Reactive: Microservices, Programming, and SystemsGet Reactive: Microservices, Programming, and Systems
Get Reactive: Microservices, Programming, and Systems
 
Lesson 3 Operation on Functions
Lesson 3 Operation on FunctionsLesson 3 Operation on Functions
Lesson 3 Operation on Functions
 
Excel function
Excel functionExcel function
Excel function
 
Processes And Job Control
Processes And Job ControlProcesses And Job Control
Processes And Job Control
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
L3 functions operations
L3 functions operationsL3 functions operations
L3 functions operations
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
 
composite functions
composite functionscomposite functions
composite functions
 
Math - Operations on Functions, Kinds of Functions
Math - Operations on Functions, Kinds of FunctionsMath - Operations on Functions, Kinds of Functions
Math - Operations on Functions, Kinds of Functions
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programming
 

Similar to “Tasks” in NetLogo 5.0beta1

Similar to “Tasks” in NetLogo 5.0beta1 (20)

Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data Science
 
Tutorial matlab
Tutorial matlabTutorial matlab
Tutorial matlab
 
Tutorialmatlab kurniawan.s
Tutorialmatlab kurniawan.sTutorialmatlab kurniawan.s
Tutorialmatlab kurniawan.s
 
Celery - A Distributed Task Queue
Celery - A Distributed Task QueueCelery - A Distributed Task Queue
Celery - A Distributed Task Queue
 
Functional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with PythonFunctional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with Python
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
 
Intro to Matlab + GUI
Intro to Matlab + GUIIntro to Matlab + GUI
Intro to Matlab + GUI
 
Intro to MATLAB GUI
Intro to MATLAB GUIIntro to MATLAB GUI
Intro to MATLAB GUI
 
Yevhen Tatarynov "From POC to High-Performance .NET applications"
Yevhen Tatarynov "From POC to High-Performance .NET applications"Yevhen Tatarynov "From POC to High-Performance .NET applications"
Yevhen Tatarynov "From POC to High-Performance .NET applications"
 
Applied numerical methods lec2
Applied numerical methods lec2Applied numerical methods lec2
Applied numerical methods lec2
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”
 
Clojure intro
Clojure introClojure intro
Clojure intro
 
Haskell
HaskellHaskell
Haskell
 
Basic operations by novi reandy sasmita
Basic operations by novi reandy sasmitaBasic operations by novi reandy sasmita
Basic operations by novi reandy sasmita
 
TDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação FuncionalTDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação Funcional
 
Haskell 101
Haskell 101Haskell 101
Haskell 101
 
Flink internals web
Flink internals web Flink internals web
Flink internals web
 
Full Stack Clojure
Full Stack ClojureFull Stack Clojure
Full Stack Clojure
 
R tutorial for a windows environment
R tutorial for a windows environmentR tutorial for a windows environment
R tutorial for a windows environment
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 

“Tasks” in NetLogo 5.0beta1