See also foreach, -> (anonymous procedure). creates 10 turtles and move them forward 5 steps For example: (run -> crt turtle-count ] 10 5) When using anonymous procedures, you can provide them with inputs, if you surround the entire call with parentheses. Trying to do the same with strings may or may not work and should not be relied on. (An example of when you must use strings is if you accept pieces of code from the user of your model.)Īnonymous procedures may freely read and/or set local variables and procedure inputs. The first run, though, will be many times slower than running the same code directly, or in an anonymous command.Īnonymous procedures are recommended over strings whenever possible. Within commands or reporter the listed args may be used just as. a reporter procedure that takes an argument x and returns a single value. However, compiled bits of code are cached by NetLogo and thus using run on the same string over and over is much faster than running different strings. Creates and reports an anonymous procedure - a command or reporter - depending on the input. Most NetLogo programs contain at least two procedures called setup and. When no NetLogoR function was built to translate a NetLogo primitive and that. The body of the procedure should use reportto report a value for the procedure. If you care about performance, note that the code must be compiled first which takes time. NetLogo Help: to-report to-report to-report procedure-nameto-report procedure-nameinput1. Note that you can't use run to define or redefine procedures. This agent runs it and reports the result. The patchreport method can be used to return a dataframe which (for this example) contains the countdown attribute of each NetLogo patch. The runresult form expects the name of a reporter, an anonymous reporter, or a string containing a reporter. to-report average-wealth this reporter returns the report mean wealth of turtles. We need to use ticks in some other algorithm. When you read the NetLogo documentation carefully, you will see that if more than one agent provides the best value of its reporter, then max-one-of. For example, we cannot just write ticks in the code. NetLogo has some useful built-in reporters that cannot be changed directly such as ticks, pi, e, world-width, and world-height. The run form expects the name of a command, an anonymous command, or a string containing commands. The keyword end marks the end of the instructions in the procedure. A reporter is a predefined procedure that returns a value and, unlike a command, cannot be a stand-alone code element. ) run string runresult reporter (runresult reporter input1. Run 1.3 runresult 1.3 run command (run command input1.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |