11/10/2022 0 Comments Netlogo lists![]() ![]() ![]() NETLOGO LISTS FREEIf you do this with a command like set my-list lput an-item my-list, then the old my-list (without an-item added) is destroyed, and the garbage collector in the Java Virtual Machine has to find it and free the memory. NetLogo's lists are immutable - once created they cannot change, and effectively, you create a different list when you add items using commands like fput and lput. ℹ️About GitHub Wiki SEE, a search engine enabler for GitHub WikisĪs GitHub blocks most GitHub Wikis from search engines.A mutable list for NetLogo created in the hope of avoiding garbage collection errors for models doing a lot of list processing. Because the delimiter is optional, when you add one you must surround the whole primitive usage with parenthesis. ![]() Observer: "1,-3,-2,85,\"hi, how are ya?\"\n0,-4,2,85,\"hi, how are ya?\"\n2,-5,3,65,\"hi, how are ya?\""Īll primitives also accept an optional delimiter argument, which is a string of a single character used to separate individual values. Observer> csv:to-string of turtles convert each turtle into a list of values we want Observer: "(turtle 0),(turtle 1),(turtle 2)" not very useful Observer> csv:to-string (list (sort turtles) ) I recommend "pre-converting" any complex values you want to retain: observer> create-turtles 3 Complex values like anonymous procedures or turtles will probably not be well-represented. Simple values like numbers, strings, and true/false should all be correctly converted. Only values that can be easily converted to strings will be correctly handled by to-string and to-row. If you're working one row at a time with single lists, you want to-row or from-row: observer> csv:from-row "" Observer: "apples,oranges,1,2\ngreen,red,3,4" Observer> csv:from-string "apples,oranges,1,2\ngreen,red,3,4" If you're working with whole files with data on separate rows, or you want to generate such a file, you want to-string and from-string: observer> csv:from-string "" You can save a CSV file using the SendTo extension, like this: send-to:file "output.csv" csv:to-string (/NetLogo/Tortoise/wiki/0-1-true-"hello"][2-5-true-".") Simple Usage You can get a CSV file using the Fetch extension, like this: fetch:user-file-async csv:from-row - convert a string into a list of values.īecause file operations operate differently in a web browser than in a desktop application, teh csv:from-file and csv:to-file primitives are not supported and will throw errors if they are used in NetLogo Web.csv:to-row - convert a "one dimensional" list into a string value.csv:from-string - convert a string into a list of lists with values.csv:to-string - convert a "two dimensional" list of lists into a string value.There are four primitives that operate the same as their equivalents in the CSV extension for desktop NetLogo. The csv extension provides convenience primitives for reading data from delimited strings to NetLogo lists, and for converting NetLogo lists to string values. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |