MongooseA living laboratory of myriad worlds.

All help topics · Link to this topic

Showing help on '$list_utils'

list utilities ($list_utils #55)

append (list,list,..) => result of concatenating the given lists
reverse (list) => reversed list
remove_duplicates (list) => list with all duplicates removed
compress (list) => list with consecutive duplicates removed
setremove_all (list,elt) => list with all occurrences of elt removed
find_insert (sortedlist,e) => index of first element > e in sortedlist
sort (list[,keys]) => sorted list
count (elt,list) => count of elt found in list.
flatten (list) => flatten all recursive lists into one list
randomly_permute (list) => list with elements randomly permuted
longest (list) => longest in list (consisting of str or list)
shortest (list) => shortest in list (as above)

make (n[,e]) => list of n copies of e
range (m,n) => {m,m+1,...,n}

arrayset (list,val,i[,j,k...]) => array modified so that list[i][j][k]==val

-- Mapping functions (take a list and do something to each element):

map_prop ({o...},prop) => list of o.(prop) for all o
map_verb ({o...},verb[,args]) => list of o:(verb)(@args) for all o
map_arg ([n,]obj,verb,{a...},args) => list of obj:(verb)(a,@args) for all a
map_builtin (objectlist, function) => applies function to all in objectlist

-- Association list functions --

An association list (alist) is a list of pairs (2-element lists), though the following functions have been generalized for lists of n-tuples (n-element lists). In each case i defaults to 1.

assoc (targ,alist[,i]) => 1st tuple in alist whose i-th element is targ
iassoc (targ,alist[,i]) => index of same.
assoc_prefix (targ,alist[,i]) => ... whose i-th element has targ as a prefix
iassoc_prefix(targ,alist[,i]) => index of same.
iassoc_sorted(targ,slist[,i]) => index of last element in sortedlist <= targ
slice (alist[,i]) => list of i-th elements
sort_alist (alist[,i]) => alist sorted on i-th elements.
amerge (alist,[tind,[dind]]) => merges tuples of alist with matching i-th elt
build_alist (list,N) => make an alist of N-intervals from list

-- Functions that suspend --

Each of these either suspends(0) as needed or takes an interval in seconds for the suspend as a first argument. See help $list_utils:<verb>.

sort_suspended iassoc_suspended sort_alist_suspended
reverse_suspended randomly_permute_suspended

:make(n[,elt]) => a list of n elements, each of which == elt. elt defaults to 0.
:map_arg*s - map_arg([n,]object,verb,@args) -- assumes the nth element of args is a list, calls object:verb(@args) with each element of the list substituted in turn, returns the list of results.
:map_builtin(objectlist,func, [@rest]) applies func to each of the objects in turn and returns the corresponding list of results. This function is mainly here for completeness -- in the vast majority of situations, a simple for loop is better.
:find_insert - find_insert(sortedlist,key) => index of first element in sortedlist > key
:remove_duplicates - remove_duplicates(list) => list as a set, i.e., all repeated elements removed.
:arrayset - arrayset(list,value,pos1,...,posn) -- returns list modified such that
:setremove_all(set,elt) => set with *all* occurences of elt removed
:append - append({a,b,c},{d,e},{},{f,g,h},...) => {a,b,c,d,e,f,g,h}
:reverse - reverse(list) => reversed list
:_reverse(@list) => reversed list
:compress - compress(list) => list with consecutive repeated elements removed, e.g.,
:sort - sort(list[,keys]) => sorts keys (assumed to be all numbers or strings) and returns list with the corresponding permutation applied to it.
:sort_suspended(interval,list[,keys]) => sorts keys (assumed to be all numbers or strings) and returns list with the corresponding permutation applied to it. keys defaults to the list itself.
:slice - slice(alist[,index]) returns a list of the index-th elements of the elements of alist, e.g.,
:assoc - assoc(target,list[,index]) returns the first element of `list' whose own index-th element is target.
:iassoc - Usage: iassoc(ANY target, LIST list [, INT index ]) => Returns the index of the first element of `list' whose own index-th element is target.
:iassoc_suspended - Usage: iassoc_suspended(ANY target, LIST list [, INT index [, INT suspend-for ]]) => Returns the index of the first element of `list' whose own index-th element is target.
:assoc_prefix - assoc_prefix(target,list[,index]) returns the first element of `list' whose own index-th element has target as a prefix.
:iassoc_prefix - iassoc_prefix(target,list[,index]) returns the index of the first element of `list' whose own index-th element has target as a prefix.
:iassoc_sorted - iassoc_sorted(target,sortedlist[,i]) => index of last element in sortedlist whose own i-th element is <= target.
:sort_alist(alist[,n]) sorts a list of tuples by n-th (1st) element.
:sort_alist_suspended - sort_alist_suspended(interval,alist[,n]) sorts a list of tuples by n-th element.
:randomly_permute(list) => list with its elements randomly permuted
:count - $list_utils:count(item, list)
:longest - $list_utils:longest(<list>)
:check_nonstring_tell_lines - check_nonstring_tell_lines(lines)
:reverse_suspended - reverse(list) => reversed list.
:_reverse(@list) => reversed list
:randomly_permute_suspended(list) => list with its elements randomly permuted
:swap_elements - swap_elements -- exchange two elements in a list
:random_item - random_item -- returns a random element of the input list.
:assoc_suspended - Usage: assoc_suspended(ANY target, LIST list [, INT index [, INT suspend-for ])) => Returns the first element of `list' whose own index-th element is target.
:amerge - amerge(list[,tindex[,dindex]]) returns an associated list such that all the tuples in the original list with the same tindex-th element are merged.
:passoc - passoc -- essentially a hashtable lookup for parallel lists.
:setmove - Usage: setmove(LIST elements, INT from, INT to)
:iassoc_new - Usage: iassoc_new(ANY target, LIST list [, INT index ]) => Returns the index of the first element of `list' whose own index-th element is target.
:build_alist - Syntax: build_alist(list, N) =>
:flatten*_suspended(LIST list_of_lists) => LIST of all lists in given list `flattened'
:max_length(strings-or-lists[, default])
:make_alist(lists[, pad])
:setremove_list(set, elt) => set minus items in elt
:implode - $list_utils:implode(list <list of strings>,string <separator>) = string of words in list separated by separator.
:tofloat - converts a list of ints to floats.
:toint - converts a list of floats to ints.
:precision - Takes a list and an optional precision.
:join - join(list, ?sep, ?omit_empty) => join list elements into string with separator
:enlist - enlist(x) => wrap x in list if not already a list, return as-is if list
:zip - zip(l1, l2, ...
:tomap - tomap(list) => convert list elements to maps (handles waifs, alists, maps)
:last - last(list, ?n) => return last n elements of list (default 1)
:replace - replace(lst, value, replacement, ?all=0);
:filter - filter(list, condition)
:names_of - Return a list of the names and object numbers of the objects in a list.
:setadd - Basically, $set_utils:union, combine lists into a single set
:count_all - ```
:head - first(list, ?n) => return first n elements of list (default 1)
:total_length - turn the sum of running length on all list elephants
:reduce(list, init, obj, verb [, @rest]) folds the list left-to-right: acc starts at init, then acc = obj:(verb)(acc, elem [, @rest]) for each element. Returns init for an empty list. This is the general fold; map_* + reduce expresses sum, total_length, average, etc.
:apply(list, selector [, ...]) maps over list. Two forms, dispatched on selector type:

Also from $generic_utils: 1 documented verb. help $generic_utils