Presentation is loading. Please wait.

Presentation is loading. Please wait.

New Mexico Computer Science For All Command Procedures in NetLogo Maureen Psaila-Dombrowski.

Similar presentations


Presentation on theme: "New Mexico Computer Science For All Command Procedures in NetLogo Maureen Psaila-Dombrowski."— Presentation transcript:

1 New Mexico Computer Science For All Command Procedures in NetLogo Maureen Psaila-Dombrowski

2 Procedures Fundamental programming concept - we decompose a program into procedures. A procedure is a named block of code It gets “invoked” or “called” by its name to get executed.

3 Procedures in NetLogo All user-defined procedures ▫Start with the keyword “to” ▫End with the keyword “end” Two types of procedures: ▫Command Procedures ▫Reporter Procedures

4 Command Procedures You have already used Command Procedures in NetLogo. The basic structure of a Command Procedure is: to command-procedure-name.... end

5 Reporter Procedures Reporter Procedures serve the same purpose as Command Procedures except ▫They use expressions. ▫They return a value. The basic structure of a Reporter is: to-report reporter-procedure-name.... report value end Not used as often – will discuss more fully later

6 Procedures in NetLogo We are already using simple procedures (setup is a procedure) to setup1 clear-all create-turtles 10 [ setxy random-xcor random-ycor set color red ] end

7 Procedures in NetLogo We can also call procedures inside other procedures to setup2 clear-all create-turtles 10 change_turtles ;; an observer procedure end to change_turtles ask turtles [ setxy random-xcor random-ycor set color red ] end

8 Procedures in NetLogo We can also call procedures inside other procedures to setup2 clear-all create-turtles 10 change_turtles ;; an observer procedure end to change_turtles ask turtles [ setxy random-xcor random-ycor set color red ] end

9 Procedures in NetLogo We can also call procedures inside other procedures to setup2 clear-all create-turtles 10 change_turtles ;; an observer procedure end to change_turtles ask turtles [ setxy random-xcor random-ycor set color red ] end

10 Why use Procedures? Decomposes your problem and your program into simple steps Makes your code easier to understand So you can reuse the length of code within a program - reduce duplicate code Makes it easier to isolate bugs in your program

11 Example: Modeling rabbit ecosystem – move, eat, birth, death,.. to rabbits_live rabbits_move rabbits_eat rabbits_reproduce rabbits_die end

12 Summary Procedures are blocks of code that can be invoked by name In NetLogo, there are two types of procedures: ▫Command Procedures ▫Reporter Procedures Why use procedures? ▫Can decompose you problem and your program into simple steps ▫Easier to understand ▫Can reuse code within the program - reduce duplicate code ▫Makes it easier to debug your program if it is broken into parts

13 Further Information If you would like more information: ▫NetLogo Manual ▫NetLogo Dictionary


Download ppt "New Mexico Computer Science For All Command Procedures in NetLogo Maureen Psaila-Dombrowski."

Similar presentations


Ads by Google