karll_arrays
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | karll_arrays [2007/02/26 21:19] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======Karll Arrays====== | ||
+ | |||
+ | =====What are Karll Arrays? | ||
+ | Karll Arrays (named after the person who contributed them to the client) | ||
+ | are named collections of items. | ||
+ | arrays, karll arrays use index refnums to refer to items. | ||
+ | |||
+ | Arrays can have any name that is a lawful C string, and array names are | ||
+ | case sensitive. | ||
+ | Any other operation on a non-existant array has not been created is a | ||
+ | "not found" error. | ||
+ | |||
+ | =====Adding items to an array===== | ||
+ | Further items may be added sequentially with no gaps in the array. | ||
+ | The canonical example of adding an item is: | ||
+ | |||
+ | $setitem(array-name $numitems(array-name) //stuff//) | ||
+ | |||
+ | You can replace an item that already exists in the array: | ||
+ | |||
+ | $setitem(array-name 0 // | ||
+ | |||
+ | Each item in an array has an //item number// and an //index number//. | ||
+ | The //item number// is what you passed to [[setitem]]. | ||
+ | is automatically generated when you change the array, and is the item's | ||
+ | sorted-order position in the array. | ||
+ | recalculation of the //index number//s when you change an array by | ||
+ | using: | ||
+ | |||
+ | $usetitem(array-name $numitems(array-name) //stuff//) | ||
+ | |||
+ | The //index number//s will be recalculated automatically the next time you | ||
+ | fetch an item from the array. | ||
+ | |||
+ | =====Getting items from an array===== | ||
+ | You can fetch an item from an array using either it's //item number// or | ||
+ | it's //index number// | ||
+ | |||
+ | $getitem(array-name 0) | ||
+ | |||
+ | To fetch by its //index number//, | ||
+ | |||
+ | $igetitem(array-name 0) | ||
+ | |||
+ | An example of traversing an entire array in sorted order: | ||
+ | |||
+ | for i from 0 to $numitems(array-name) { | ||
+ | echo $igetitem(array-name $i); | ||
+ | }; | ||
+ | |||
+ | =====Finding values in an array===== | ||
+ | |||
+ | =====Using an array to hold wildcard patterns===== | ||
+ | |||
+ | =====Using an array to hold strings to be matched===== | ||
+ | |||
+ | =====Using an array with duplicate items===== | ||
+ | |||
+ | =====Deleting items from an array===== | ||
+ | When you delete an item from an array, all the items numbers above it move | ||
+ | down one spot. If you have an array with 4 items (0 to 3) | ||
+ | and then delete item 1, the old item 2 becomes the new item 1, and the old | ||
+ | item 3 becomes the new item 2. There are never gaps in an array. | ||
+ | |||
+ | When you delete the final item from an array, the array is automatically | ||
+ | destroyed. | ||
+ | |||
+ | You can atomically delete an array with [[delarray]]. | ||
+ | |||
+ | |||
+ | ======Functions: | ||
+ | ^ Function name ^ Description ^ | ||
+ | | [[setitem]](// | ||
+ | | [[usetitem]](// | ||
+ | | [[getitem]](// | ||
+ | | [[igetitem]](// | ||
+ | | [[numitems]](// | ||
+ | | [[matchitem]](// | ||
+ | | [[rmatchitem]](// | ||
+ | | [[gettmatch]](// | ||
+ | | [[getmatches]](// | ||
+ | | [[getrmatches]](// | ||
+ | | [[igetmatches]](// | ||
+ | | [[igetrmatches]](// | ||
+ | | [[finditem]](// | ||
+ | | [[ifinditem]](// | ||
+ | | [[finditems]](// | ||
+ | | [[ifinditems]](// | ||
+ | | [[ifindfirst]](// | ||
+ | | [[indextoitem]](// | ||
+ | | [[itemtoindex]](// | ||
+ | | [[delitem]](// | ||
+ | | [[delitems]](// | ||
+ | | [[delarray]](// | ||
+ | | [[numarrays]]() | Return the number of arrays currently active | | ||
+ | | [[getarrays]]() | Return a wordlist of names of all current arrays. | | ||
+ | | [[listarray]](// | ||
+ | |||
+ | ======History: | ||
+ | Karll Arrays first appeared in "plus 3" (post-ircII, | ||
+ | Many functions have been added since the start. | ||
karll_arrays.txt · Last modified: 2007/02/26 21:19 by 127.0.0.1