![]() ![]() lt:right cursor : move the cursor one element to the right, returning the item stored in its list there.lt:left cursor : move the cursor one element to the left, returning the item stored in its list there.lt:foreach-depth-first list command-block : execute the command-block for each item in the list recursively iterating any elements of list that are mutable lists.lt:foreach list command-block : execute the command-block for each item in the list.(This is a bit more forgiving than NetLogo's map command, which stipulates that all lists must have the same length.) In the multi-argument form, the list returned will have the same length as the shortest list in the arguments. ) : run the reporter on each element of list and return a mutable list containing the result. lt:map reporter list (lt:map reporter list1 list2 list3.lt:cursor list : return a cursor for the list, starting at the front.The list will not contain any number larger than stop (if it is more than start smaller than stop otherwise). lt:range start stop increment : return a list of numbers starting at start, incrementing by increment (optional, default 1 if start lt:make : return a new, empty mutable list.lt:from-list logolist : return a mutable list constructed from the NetLogo list argument logolist.lt:from-agentset agentset : return a list containing each of the turtles, patches or links in agentset, in arbitrary order.Modifications to the copy will not affect the list, and vice versa. lt:copy list : return a list created by copying the list.Where a list is stipulated as an argument, this must be a mutable list unless otherwise stated. The following summarizes the commands implemented. To allow you to edit the list at points other than the front, you can get a cursor which you can move up and down the list, and insert, overwrite and delete at the cursor. A future implementation may make this faster, but this implementation is a list 'purist' and does not provide 'random' access to elements of the list (beyond, for convenience, the tenth element), so there is no equivalent of the item command. Adding things to the end of the list will be slower in comparison, because doing so entails iterating to the end of the list. It is generally there when you want an ordered collection of items where typically, you only care about the first item on the list and the rest. These problems aside, a mutable list is a useful data structure in its own right. This is a problem you cannot fix by giving Java/NetLogo more RAM! If you do this enough, you will find the garbage collector running to much - and when it reaches 98% of the execution effort of the program, Java will fail with an OutOfMemoryException. If 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. A mutable list for NetLogo created in the hope of avoiding garbage collection errors for models doing a lot of list processing. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |