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

Slides:



Advertisements
Similar presentations
User Defined Functions
Advertisements

Sub and Function Procedures
 Functions breakdown: Functions purpose Modularity Declaring and defining a function Calling a function Parameter passing Returning a value Reusability.
Week 7 DO NOW QUESTIONS. Question: In the following segment of code, “food-location” is a ___? breed [ foragers forager ] breed [ followers follower ]
Day 1 Goal: To create a model of people hunting in the forest for mushrooms and then start working on improving their mushroom hunting ability mathematically.
New Mexico Computer Science For All
New Mexico Computer Science For All Local Variables in Netlogo Maureen Psaila-Dombrowski.
New Mexico Computer Science For All Breeds and Shapes in NetLogo Maureen Psaila-Dombrowski.
VBA Modules, Functions, Variables, and Constants
New Mexico Computer Science For All More Looping in NetLogo Maureen Psaila-Dombrowski.
New Mexico Computer Science For All Abstraction in Modeling and Simulation Maureen Psaila-Dombrowski.
Department of Computer Science What is NetLogo UH-DMML  Multi-agent programmable modeling environment  Well suited for modeling complex systems evolving.
New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski.
New Mexico Computer Science For All Statements and Expressions in NetLogo Maureen Psaila-Dombrowski.
2-Day Introduction to Agent-Based Modelling Day 1: Session 4 Networks.
CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.
Week 11 DO NOW QUESTIONS. An ask turtles block is a set of instructions that is issued to every turtle. Even though computers can do things very quickly,
1 Documenting Your Project. 2 Documenting your Project Insert Banner Comments in your code Comment - coding statement used by humans not the compiler.
Chapter 6 Functions 1. Opening Problem 2 Find the sum of integers from 1 to 10, from 20 to 37, and from 35 to 49, respectively.
New Mexico Computer Science For All Population Dynamics: Birth and Death Maureen Psaila-Dombrowski.
New Mexico Computer Science For All Interface Input in NetLogo Maureen Psaila-Dombrowski.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 3 Simple.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
Methods in Java CSC1401. Overview In this session, we are going to see how to create class-level methods in Java.
New Mexico Computer Science For All Interface Output in NetLogo (Part 1) Maureen Psaila-Dombrowski.
Introduction to Algorithms using Netlogo. What’s an Algorithm Definitions of Algorithm on the Web: –A procedure or formula for solving a problem.
Week 9 DO NOW QUESTIONS. Question: If the following procedure is executed after 1 turtle is created in the program, what shape is created on the NetLogo.
Agent-Based Modeling and Simulation (ABMS) Bertan Badur Department of Management Information Systems Boğaziçi University.
142 F -1 Functions chapter 3 of the text int main(void) { double x,y,z; … x = cube(y/3.0); … printf(“%f cubed is %f”,x,cube(x)); … return 0; } double cube(double.
Simple Functions and Names Sec 9-4 Web Design. Objectives The student will: Know how to create a simple function in Python. Know how to call a function.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Week 2 DO NOW QUESTIONS. In this procedure the programmer intended to clear all the turtles and patches and make a new turtle of size 3 with the pen down,
New Mexico Computer Science For All Variables and Scope Maureen Psaila-Dombrowski.
New Mexico Computer Science For All Creating Turtles Maureen Psaila-Dombrowski.
New Mexico Computer Science For All Patches and Agent/Environment Interactions Maureen Psaila-Dombrowski.
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Introduction to Computing Using Python Namespaces – Local and Global  The Purpose of Functions  Global versus Local Namespaces  The Program Stack 
New Mexico Computer Science For All Search Algorithms Maureen Psaila-Dombrowski.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Automating Component Test Insertion into DØRunII CTBUILD Software Packages Mariano A. Zimmler New York University Supervisor Dr. David J. Ritchie Computing.
Introduction to Functions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Week 3 DO NOW QUESTIONS. In this setup procedure the programmer intended to create one turtle of each color: red, green, and blue. What went wrong? to.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
The Functions and Purposes of Translators Translators, Interpreters and Compilers - High Level Languages.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
M10 WS11:Krankenhausbedarfsplanung The World as We See It given by Gabriel Wurzer and Wolfgang E. Lorenz
Georgia Institute of Technology Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology North Jeddah Branch King Abdulaziz University.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Functions. 2 Modularity What is a function? A named block of code Sometimes called a ‘module’, ‘method’ or a ‘procedure’ Some examples that you know are:
M10 WS11:Krankenhausbedarfsplanung More, More and Even-More More given by Gabriel Wurzer and Wolfgang E. Lorenz
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING
Management Information Systems
Management Information Systems
UNIT 3 – LESSON 5 Creating Functions.
Functions.
Chapter 3 Simple Functions
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
Chapter 4 Functions Objectives
Namespaces – Local and Global
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
CPS120: Introduction to Computer Science
Creating Stored Procedures and Functions
Introduction to Computer Science
Modules Programming Guides.
Namespaces – Local and Global
Presentation transcript:

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

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.

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

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

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

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

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

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

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

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

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

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

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