Open the Code tab and enter the following command procedure stub. Here to and end are the NetLogo keywords used to creat
Posted: Tue Jul 05, 2022 10:25 am
Open the Code tab and enter the following commandprocedure stub.
Here to and end are the NetLogo keywordsused to create a command procedure, and trystuff is thename we give the procedure. Call the first line the commanddeclaration. Between the command declaration and end isthe procedure body, so this command procedure has an emptybody.
Let’s change that. Start entering each of the commands fromthe Simple Computations exercise 1. Notice how NetLogowarns you of a syntax error as soon as you enter the first line.Prefix a semicolon to this line to turn it into a comment, whichNetLogo ignores.
Recall that some of these commands would not run and the commandline. Each time you add a line, change to the Command Line and runthis procedure by entering trystuff. Whenever a line creates aproblem, comment it out. Is there any difference between whichlines you could run at the Command Line and which work finein trystuff? In the Info tab, explain.
We often use command procedures to test our functions. Forexample, approach the simple test of the sq function fromthe Reporter Procedures exercise in a slightly moreformal manner. Copy the following command procedure to the bottomof your Code tab. Then enter test-sq at theNetLogo command line in order run this command procedure and testyour sq function. (If your sq function does notpass this test, fix it!)
Similarly, test your xpsq function fromthe Reporter Procedures exercises by adding the followingtest to your Code tab and running it at the commandline.
We may use command procedures to change the values of globalvariables. Again, make sure you have declared a globalvariable x. Add the following commandprocedure to your Code tab. (As always, usethe Check button to check your work.)
Does this sqx procedure implement a purefunction? Why or why not? (Explain in the Info tab.)
Try to find a way to use this sqx commandprocedure (below) to produce the values we so easilyproduced with the sq function from the ReporterProcedures exercises. What problems do you run into? Forexample, what happens if you try to print (sqx 2)?
What have you learned about using functions (reporterprocedures) rather than command procedures to produce neededvalues? Describe some advantages of the reporter procedure (sq)from the Reporter Procedures exercises. over this commandprocedure (sqx)
At the bottom of the Code tab, createa test-nextVP command procedure to testthe nextVP function from the ReporterProcedures exercises. Test that the resultis 0 when x=0 and 1 when x=1. Atthe NetLogo command line, enter test-nextVP to confirmthat your implementation of nextVP behaves as expected.(See the Logistic Growth lecture for details.)
Here to and end are the NetLogo keywordsused to create a command procedure, and trystuff is thename we give the procedure. Call the first line the commanddeclaration. Between the command declaration and end isthe procedure body, so this command procedure has an emptybody.
Let’s change that. Start entering each of the commands fromthe Simple Computations exercise 1. Notice how NetLogowarns you of a syntax error as soon as you enter the first line.Prefix a semicolon to this line to turn it into a comment, whichNetLogo ignores.
Recall that some of these commands would not run and the commandline. Each time you add a line, change to the Command Line and runthis procedure by entering trystuff. Whenever a line creates aproblem, comment it out. Is there any difference between whichlines you could run at the Command Line and which work finein trystuff? In the Info tab, explain.
We often use command procedures to test our functions. Forexample, approach the simple test of the sq function fromthe Reporter Procedures exercise in a slightly moreformal manner. Copy the following command procedure to the bottomof your Code tab. Then enter test-sq at theNetLogo command line in order run this command procedure and testyour sq function. (If your sq function does notpass this test, fix it!)
Similarly, test your xpsq function fromthe Reporter Procedures exercises by adding the followingtest to your Code tab and running it at the commandline.
We may use command procedures to change the values of globalvariables. Again, make sure you have declared a globalvariable x. Add the following commandprocedure to your Code tab. (As always, usethe Check button to check your work.)
Does this sqx procedure implement a purefunction? Why or why not? (Explain in the Info tab.)
Try to find a way to use this sqx commandprocedure (below) to produce the values we so easilyproduced with the sq function from the ReporterProcedures exercises. What problems do you run into? Forexample, what happens if you try to print (sqx 2)?
What have you learned about using functions (reporterprocedures) rather than command procedures to produce neededvalues? Describe some advantages of the reporter procedure (sq)from the Reporter Procedures exercises. over this commandprocedure (sqx)
At the bottom of the Code tab, createa test-nextVP command procedure to testthe nextVP function from the ReporterProcedures exercises. Test that the resultis 0 when x=0 and 1 when x=1. Atthe NetLogo command line, enter test-nextVP to confirmthat your implementation of nextVP behaves as expected.(See the Logistic Growth lecture for details.)