Reports a sorted list of numbers, strings, or agents.
If the input contains no numbers, strings, or agents, the result is the empty list.
If the input contains at least one number, the numbers in the list are sorted in ascending order and a new list reported; non-numbers are ignored.
Or, if the input contains at least one string, the strings in the list are sorted in ascending order and a new list reported; non-strings are ignored.
Or, if the input is an agentset or a list containing at least one agent, a sorted list of agents (never an agentset) is reported; non-agents are ignored. Agents are sorted in the same order the < operator uses. (Patches are sorted with the top left-most patch first and the bottom right-most patch last, turtles are sorted by who
number).
show sort [3 1 4 2] => [1 2 3 4] show sort [2 1 "a"] => [1 2] show sort (list "a" "c" "b" (patch 0 0)) => ["a" "b" "c"] show sort (list (patch 0 0) (patch 0 1) (patch 1 0)) => [(patch 0 1) (patch 0 0) (patch 1 0)] ;; label patches with numbers in left-to-right, top-to-bottom order let n 0 foreach sort patches [ the-patch -> ask the-patch [ set plabel n set n n + 1 ] ] ;; some additional examples to clarify behavior in strange cases show sort (list patch 0 0 patch 0 1 patch 1 0 turtle 0 turtle 1) ; turtles are always sorted lower than patches => [(turtle 0) (turtle 1) (patch 0 1) (patch 0 0) (patch 1 0)] show sort (list nobody false true) ; booleans and nobody cannot be sorted => [] show sort (list [1 2 3] turtles) ; lists and agentsets are not included if they are inside a list passed to sort => []
Take me to the full NetLogo Dictionary