list utilities #47

Parent #72Owner #29Flags readSource hellcore/hellcore.db

Aliases: list_utilities

71 verbs · 12 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
makethis none thisrxd#4717
range range_suspendedthis none thisrxd#4711
map_prop*ertythis none thisrxd#4710
map_verbthis none thisrxd#4710
map_arg*sthis none thisrxd#4717
map_builtinthis none thisrxd#4714
find_insertthis none thisrxd#4721
remove_duplicatesthis none thisrxd#476
arraysetthis none thisrxd#478
setremove_allthis none thisrxd#476
appendthis none thisrxd#479
reversethis none thisrxd#477
_reversethis none thisrxd#479
compressthis none thisrxd#4714
sortthis none thisrxd#4714
sort_suspendedthis none thisrxd#4719
slicethis none thisrxd#4720
assocthis none thisrxd#479
iassocthis none thisrxd#4712
iassoc_suspendedthis none thisrxd#4714
assoc_prefixthis none thisrxd#478
iassoc_prefixthis none thisrxd#478
iassoc_sortedthis none thisrxd#4722
sort_alistthis none thisrxd#4757
sort_alist_suspendedthis none thisrxd#4735
randomly_permute randomizethis none thisrxd#477
countthis none thisrxd#4712
flatten flatten_suspendedthis none thisrxd#4711
longest shortestthis none thisrxd#4719
check_nonstring_tell_linesthis none thisrxd#4710
reverse_suspendedthis none thisrxd#474
_reverse_suspendedthis none thisrxd#4711
randomly_permute_suspendedthis none thisrxd#479
swap_elementsthis none thisrxd#4717
random_item random_elementthis none thisrxd#4714
assoc_suspendedthis none thisrxd#4716
amergethis none thisrxd#4721
passocthis none thisrx#4711
setmovethis none thisrxd#4710
iassoc_newthis none thisrxd#4717
build_alistthis none thisrxd#4717
sort_valuethis none thisrxd#4711
find_insert_valuethis none thisrxd#4722
sort_propthis none thisrxd#479
find_insert_propthis none thisrxd#4719
map_verb_valuethis none thisrxd#4711
amerge_suspendedthis none thisrxd#4723
setremove_all_listthis none thisrxd#478
list_is_a is_athis none thisrxd#477
sort_cardinalthis none thisrxd#4720
find_insert_cardinalthis none thisrxd#4723
same_setsthis none thisrxd#4714
sort_cardinal_suspendedthis none thisrxd#4721
randomthis none thisrxd#475
count_listthis none thisrxd#4714
count_list_suspendedthis none thisrxd#4714
group_objectsthis none thisrxd#4722
as_listthis none thisrxd#477
sumthis none thisrxd#476
foldlthis none thisrxd#477
remove_if remove_if_not remove_if_suspended remove_if_not_suspendedthis none thisrxd#4718
tolistthis none thisrxd#471
make_alistthis none thisrxd#4714
break_atthis none thisrxd#4713
is_one_ofthis none thisrxd#478
sort_callbackthis none thisrxd#4710
_find_insert_callbackthis none thisrxd#4720
arethis none thisrxd#4711
valid gamevalidthis none thisrxd#478
implodethis none thisrxd#4710
sort_prop_suspendedthis none thisrxd#4710

Properties

PropertyDefinerFlagsOwnerValue
nonstring_tell_lines#47r#29{}
help_msg#72rc#29
list of 59{"*** NOTE: for more help on any verb, do 'help $lu:verbname'.", "", "$list_utils ($lu) provide verbs for working with lists, creating lists, ", "and working with lists-of-lists (association lists or alists.) Verbs marked ", "with asterisks (*) have suspending versions, named \"(verbname)_suspended\".", "", " Standard operations:", ":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]) => list, sorted in ascending order", ":count (elt,list) => count of elt found in list", ":flatten (list) => turn list of lists into one list", ":randomly_permute *(list) => shuffled list", ":longest (list) => longest in list (strings or lists)", ":shortest (list) => shortest in list (strings or lists)", ":random (list) => use list[random($)] instead", ":count_list * (list) => { {item1, count1}, {item2, count2}...}", ":list_is_a (list, obj) => elts from list that descend from obj", ":is_one_of (obj, list) => elts of list that are parents of obj", "", ":remove_if(_not) * (o, v, list, @args)", " => list with elements removed which return true (false) for o:v(elt, @args)", "", ":make (n[,e]) => list of n copies of e", ":range (m,n) => {m,m+1,...,n}", ":as_list (v) => typeof(v) == LIST ? v | {v}", ":break_at (list, n) => break list into chunks of max size n", "", ":arrayset (list,val,i[,j,k...])", " => list modified so that list[i][j][k]==val", "", " Mapping:", ":map_prop (obj-list,prop) => list of o.(prop) for all o", ":map_verb (obj-list,verb[,args]) => list of o:(verb)(@args) for all o", ":map_arg ([n,]obj,verb,{x...},args) => list of o:(verb)(x,@args) for all x", ":map_builtin (obj-list, funcname) => list of funcname(o) for all o", "", " Assocation lists (lists of 'tuples', or secondary lists):", ":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", ":make_alist (list, list, ...) => make an alist of paired elements from lists", "", " Special use:", ":same_sets (list1, list2) => do lists contain identical elements?", ":sort_cardinal_suspended(list) => sort list of exits, by direction", "", ":group_objects (obj-list, parent-list1, parent-list2, ...)", " => {obj-list1, obj-list2, ..., unclassified-objs}"}
aliases#1rc#29{"list_utilities"}
description#1rc#29{"This is the list utilities utility package. See `help $list_utils' for more details."}
object_size#1r#29{46615, 1298433815}
hidden_verbs#1rc#29<clear>
phelp_msg#1rc#29<clear>
weight#1rc#29<clear>
owner_verbs#1rc#29<clear>
plural_name#1rc#29<clear>
client_image#1rc#29<clear>
listening#1rc#29<clear>

Ancestry

Ancestors (nearest first): #72 Generic Utilities Package#1 root

Children: none

Call graph

calls n47_1 #47:range n48_8 #48:suspend_if_needed n47_1->n48_8 n47_3 #47:map_verb n47_3->n47_3 n47_5 #47:map_builtin n47_5->n47_5 n47_8 #47:arrayset n47_8->n47_8 n47_10 #47:append n47_10->n47_10 n47_12 #47:_reverse n47_12->n47_12 n47_14 #47:sort n47_14->n48_8 n47_6 #47:find_insert n47_14->n47_6 n47_15 #47:sort_suspended n47_15->n48_8 n47_15->n47_6 n47_23 #47:sort_alist n47_23->n47_14 n47_23->n47_23 n47_16 #47:slice n47_23->n47_16 n47_24 #47:sort_alist_suspended n47_24->n48_8 n47_24->n47_14 n47_24->n47_16 n47_24->n47_24 n47_27 #47:flatten n47_27->n48_8 n47_27->n47_27 n47_30 #47:reverse_suspended n47_31 #47:_reverse_suspended n47_30->n47_31 n47_31->n48_8 n47_31->n47_31 n47_35 #47:assoc_suspended n47_35->n48_8 n47_36 #47:amerge n47_36->n47_23 n47_33 #47:swap_elements n47_36->n47_33 n47_41 #47:sort_value n47_42 #47:find_insert_value n47_41->n47_42 n47_43 #47:sort_prop n47_44 #47:find_insert_prop n47_43->n47_44 n47_45 #47:map_verb_value n47_45->n47_3 n47_46 #47:amerge_suspended n47_46->n48_8 n47_46->n47_24 n47_46->n47_33 n47_49 #47:sort_cardinal n47_49->n47_43 n47_50 #47:find_insert_cardinal n47_49->n47_50 n47_52 #47:sort_cardinal_suspended n47_52->n48_8 n47_52->n47_43 n47_52->n47_50 n47_54 #47:count_list n47_18 #47:iassoc n47_54->n47_18 n47_55 #47:count_list_suspended n47_55->n47_18 n47_56 #47:group_objects n47_56->n48_8 n47_0 #47:make n47_56->n47_0 n47_60 #47:remove_if n47_60->n48_8 n47_65 #47:sort_callback n47_66 #47:_find_insert_callback n47_65->n47_66 n47_70 #47:sort_prop_suspended n47_70->n47_44

Source

make

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1":make(n[,elt]) => a list of n elements, each of which == elt. elt defaults to 0.";
2{n, ?elt = 0} = args;
3if (n < 0)
4return E_INVARG;
5endif
6ret = {};
7build = {elt};
8while (1)
9if (n % 2)
10ret = {@ret, @build};
11endif
12if (n = n / 2)
13build = {@build, @build};
14else
15return ret;
16endif
17endwhile

range range_suspended

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1":range([m,]n) => {m,m+1,...,n}";
2{?m = 1, n} = args;
3ret = {};
4suspend = verb == "range_suspended";
5for k in [m..n]
6ret = {@ret, k};
7if (suspend)
8$cu:sin();
9endif
10endfor
11return ret;

map_prop*erty

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

none

Source

1set_task_perms(caller_perms());
2{objs, prop} = args;
3if (length(objs) > 50)
4return {@this:map_prop(objs[1..$ / 2], prop), @this:map_prop(objs[($ / 2) + 1..$], prop)};
5endif
6strs = {};
7for foo in (objs)
8strs = {@strs, foo.(prop)};
9endfor
10return strs;

map_verb

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1set_task_perms(caller_perms());
2{objs, vrb, @rest} = args;
3if (length(objs) > 50)
4return {@this:map_verb(@listset(args, objs[1..$ / 2], 1)), @this:map_verb(@listset(args, objs[($ / 2) + 1..$], 1))};
5endif
6strs = {};
7for o in (objs)
8strs = {@strs, o:(vrb)(@rest)};
9endfor
10return strs;

map_arg*s

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

none

Source

1"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.  n defaults to 1.";
2"map_verb_arg(o,v,{a...},a2,a3,a4,a5)={o:v(a,a2,a3,a4,a5),...}";
3"map_verb_arg(4,o,v,a1,a2,a3,{a...},a5)={o:v(a1,a2,a3,a,a5),...}";
4set_task_perms(caller_perms());
5n = args[1];
6if (typeof(n) == INT)
7{object, verb, @rest} = args[2..$];
8else
9object = n;
10n = 1;
11{verb, @rest} = args[2..$];
12endif
13results = {};
14for a in (rest[n])
15results = listappend(results, object:(verb)(@listset(rest, a, n)));
16endfor
17return results;

map_builtin

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1":map_builtin(objectlist,func) 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.";
2set_task_perms(caller_perms());
3{objs, builtin} = args;
4if (!`function_info(builtin) ! E_INVARG => 0')
5return E_INVARG;
6endif
7if (length(objs) > 100)
8return {@this:map_builtin(objs[1..$ / 2], builtin), @this:map_builtin(objs[($ / 2) + 1..$], builtin)};
9endif
10strs = {};
11for foo in (objs)
12strs = {@strs, call_function(builtin, foo)};
13endfor
14return strs;

find_insert

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1"find_insert(sortedlist,key) => index of first element in sortedlist > key";
2"  sortedlist is assumed to be sorted in increasing order and the number returned is anywhere from 1 to length(sortedlist)+1, inclusive.";
3{lst, key} = args;
4if ((r = length(lst)) < 25)
5for l in [1..r]
6if (lst[l] > key)
7return l;
8endif
9endfor
10return r + 1;
11else
12l = 1;
13while (r >= l)
14if (key < lst[i = (r + l) / 2])
15r = i - 1;
16else
17l = i + 1;
18endif
19endwhile
20return l;
21endif

remove_duplicates

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1"remove_duplicates(list) => list as a set, i.e., all repeated elements removed.";
2out = {};
3for x in (args[1])
4out = setadd(out, x);
5endfor
6return out;

arrayset

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1"arrayset(list,value,pos1,...,posn) -- returns list modified such that";
2"  list[pos1][pos2][...][posn] == value";
3if (length(args) > 3)
4return listset(@listset(args[1..3], this:arrayset(@listset(listdelete(args, 3), args[1][args[3]], 1)), 2));
5"... Rog's entry in the Obfuscated MOO-Code Contest...";
6else
7return listset(@args);
8endif

setremove_all

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1":setremove_all(set,elt) => set with *all* occurences of elt removed";
2{set, what} = args;
3while (w = what in set)
4set[w..w] = {};
5endwhile
6return set;

append

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1"append({a,b,c},{d,e},{},{f,g,h},...) =>  {a,b,c,d,e,f,g,h}";
2if (length(args) > 50)
3return {@this:append(@args[1..$ / 2]), @this:append(@args[($ / 2) + 1..$])};
4endif
5l = {};
6for a in (args)
7l = {@l, @a};
8endfor
9return l;

reverse

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1"reverse(list) => reversed list";
2old = args[1];
3new = {};
4for i in [1..length(old)]
5new = {old[i], @new};
6endfor
7return new;

_reverse

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1":_reverse(@list) => reversed list";
2if (length(args) > 50)
3return {@this:_reverse(@args[($ / 2) + 1..$]), @this:_reverse(@args[1..$ / 2])};
4endif
5l = {};
6for a in (args)
7l = listinsert(l, a);
8endfor
9return l;

compress

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

none

Source

1"compress(list) => list with consecutive repeated elements removed, e.g.,";
2"compress({a,b,b,c,b,b,b,d,d,e}) => {a,b,c,b,d,e}";
3if (l = args[1])
4out = {last = l[1]};
5for x in (listdelete(l, 1))
6if (x != last)
7out = listappend(out, x);
8last = x;
9endif
10endfor
11return out;
12else
13return l;
14endif

sort

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1"sort(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.";
2"sort({x1,x3,x2},{1,3,2}) => {x1,x2,x3}";
3lst = args[1];
4unsorted_keys = (use_sorted_lst = length(args) >= 2) ? args[2] | lst;
5sorted_lst = sorted_keys = {};
6for e in (unsorted_keys)
7$cu:sin();
8l = this:find_insert(sorted_keys, e);
9sorted_keys = listinsert(sorted_keys, e, l);
10if (use_sorted_lst)
11sorted_lst = listinsert(sorted_lst, lst[length(sorted_keys)], l);
12endif
13endfor
14return sorted_lst || sorted_keys;

sort_suspended

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1":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.";
2"does suspend(interval) as needed.";
3set_task_perms(caller_perms());
4interval = args[1];
5if (typeof(interval) != INT)
6return E_ARGS;
7endif
8lst = args[2];
9unsorted_keys = (use_sorted_lst = length(args) >= 3) ? args[3] | lst;
10sorted_lst = sorted_keys = {};
11for e in (unsorted_keys)
12l = this:find_insert(sorted_keys, e);
13sorted_keys[l..l - 1] = {e};
14if (use_sorted_lst)
15sorted_lst[l..l - 1] = {lst[length(sorted_keys)]};
16endif
17$command_utils:suspend_if_needed(interval);
18endfor
19return sorted_lst || sorted_keys;

slice

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1"slice(alist[,index]) returns a list of the index-th elements of the elements of alist, e.g., ";
2"    slice({{\"z\",1},{\"y\",2},{\"x\",5}},2) => {1,2,5}.";
3"index defaults to 1 and may also be a nonempty list, e.g., ";
4"    slice({{\"z\",1,3},{\"y\",2,4}},{2,1}) => {{1,\"z\"},{2,\"y\"}}";
5{thelist, ?ind = 1} = args;
6slice = {};
7if (typeof(ind) == LIST)
8for elt in (thelist)
9s = {elt[ind[1]]};
10for i in (listdelete(ind, 1))
11s = {@s, elt[i]};
12endfor
13slice = {@slice, s};
14endfor
15else
16for elt in (thelist)
17slice = {@slice, elt[ind]};
18endfor
19endif
20return slice;

assoc

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1"assoc(target,list[,index]) returns the first element of `list' whose own index-th element is target.  Index defaults to 1.";
2"returns {} if no such element is found";
3{target, thelist, ?indx = 1} = args;
4for t in (thelist)
5if ((typeof(t) == LIST) && `t[indx] == target ! E_RANGE => 0')
6return t;
7endif
8endfor
9return {};

iassoc

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1"Copied from Moo_tilities (#332):iassoc by Mooshie (#106469) Wed Mar 18 19:27:51 1998 PST";
2"Usage: iassoc(ANY target, LIST list [, INT index ]) => Returns the index of the first element of `list' whose own index-th element is target.  Index defaults to 1.";
3"Returns 0 if no such element is found.";
4{target, thelist, ?indx = 1} = args;
5for element in (thelist)
6if (`element[indx] == target ! E_RANGE, E_TYPE => 0')
7if (typeof(element) == LIST)
8return element in thelist;
9endif
10endif
11endfor
12return 0;

iassoc_suspended

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1"Copied from Moo_tilities (#332):iassoc_suspended by Mooshie (#106469) Wed Mar 18 19:27:53 1998 PST";
2"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. Index defaults to 1.";
3"Returns 0 if no such element is found.";
4"Suspends as needed. Suspend length defaults to 0.";
5set_task_perms(caller_perms());
6{target, thelist, ?indx = 1, ?suspend_for = 0} = args;
7for element in (thelist)
8if (`element[indx] == target ! E_RANGE, E_TYPE => 0' && (typeof(element) == LIST))
9return element in thelist;
10endif
11yield suspend_for;
12endfor
13return 0;
14"Mooshie (#106469) - Tue Feb 10, PST - :assoc_suspended does a set_task_perms, why shouldn't this?";

assoc_prefix

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

none

Source

1"assoc_prefix(target,list[,index]) returns the first element of `list' whose own index-th element has target as a prefix.  Index defaults to 1.";
2{target, thelist, ?indx = 1} = args;
3for t in (thelist)
4if ((typeof(t) == LIST) && ((length(t) >= indx) && (index(t[indx], target) == 1)))
5return t;
6endif
7endfor
8return {};

iassoc_prefix

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

none

Source

1"iassoc_prefix(target,list[,index]) returns the index of the first element of `list' whose own index-th element has target as a prefix.  Index defaults to 1.";
2{target, lst, ?indx = 1} = args;
3for i in [1..length(lst)]
4if ((typeof(lsti = lst[i]) == LIST) && ((length(lsti) >= indx) && (index(lsti[indx], target) == 1)))
5return i;
6endif
7endfor
8return 0;

iassoc_sorted

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1"iassoc_sorted(target,sortedlist[,i]) => index of last element in sortedlist whose own i-th element is <= target.  i defaults to 1.";
2"  sortedlist is assumed to be sorted in increasing order and the number returned is anywhere from 0 to length(sortedlist), inclusive.";
3{target, lst, ?indx = 1} = args;
4if ((r = length(lst)) < 25)
5for l in [1..r]
6if (target < lst[l][indx])
7return l - 1;
8endif
9endfor
10return r;
11else
12l = 0;
13r = r + 1;
14while ((r - 1) > l)
15if (target < lst[i = (r + l) / 2][indx])
16r = i;
17else
18l = i;
19endif
20endwhile
21return l;
22endif

sort_alist

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1":sort_alist(alist[,n]) sorts a list of tuples by n-th (1st) element.";
2{alist, ?sort_on = 1} = args;
3if ((alist_length = length(alist)) < 25)
4"use insertion sort on short lists";
5return this:sort(alist, this:slice(@args));
6endif
7left_index = alist_length / 2;
8right_index = (alist_length + 1) / 2;
9left_sublist = this:sort_alist(alist[1..left_index], sort_on);
10right_sublist = this:sort_alist(alist[left_index + 1..alist_length], sort_on);
11"...";
12"... merge ...";
13"...";
14left_key = left_sublist[left_index][sort_on];
15right_key = right_sublist[right_index][sort_on];
16if (left_key > right_key)
17merged_list = {};
18else
19"... alist_length >= 25 implies right_index >= 2...";
20"... move right_index downward until left_key > right_key...";
21r = right_index - 1;
22while (left_key <= (right_key = right_sublist[r][sort_on]))
23if (r = r - 1)
24else
25return {@left_sublist, @right_sublist};
26endif
27endwhile
28merged_list = right_sublist[r + 1..right_index];
29right_index = r;
30endif
31while (l = left_index - 1)
32"... left_key > right_key ...";
33"... move left_index downward until left_key <= right_key...";
34while ((left_key = left_sublist[l][sort_on]) > right_key)
35if (l = l - 1)
36else
37return {@right_sublist[1..right_index], @left_sublist[1..left_index], @merged_list};
38endif
39endwhile
40merged_list[1..0] = left_sublist[l + 1..left_index];
41left_index = l;
42"... left_key <= right_key ...";
43if (r = right_index - 1)
44"... move right_index downward until left_key > right_key...";
45while (left_key <= (right_key = right_sublist[r][sort_on]))
46if (r = r - 1)
47else
48return {@left_sublist[1..left_index], @right_sublist[1..right_index], @merged_list};
49endif
50endwhile
51merged_list[1..0] = right_sublist[r + 1..right_index];
52right_index = r;
53else
54return {@left_sublist[1..left_index], right_sublist[1], @merged_list};
55endif
56endwhile
57return {@right_sublist[1..right_index], left_sublist[1], @merged_list};

sort_alist_suspended

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1"sort_alist_suspended(interval,alist[,n]) sorts a list of tuples by n-th element.  n defaults to 1.  Calls suspend(interval) as necessary.";
2set_task_perms(caller_perms());
3"... so it can be killed...";
4{interval, alist, ?sort_on = 1} = args;
5if ((alist_length = length(alist)) < 10)
6"insertion sort on short lists";
7$command_utils:suspend_if_needed(interval);
8return this:sort(alist, this:slice(@listdelete(args, 1)));
9endif
10"variables specially expanded for the anal-retentive";
11left_index = alist_length / 2;
12right_index = (alist_length + 1) / 2;
13left_sublist = this:sort_alist_suspended(interval, alist[1..left_index], sort_on);
14right_sublist = this:sort_alist_suspended(interval, alist[left_index + 1..alist_length], sort_on);
15left_element = left_sublist[left_index];
16right_element = right_sublist[right_index];
17merged_list = {};
18while (1)
19$command_utils:suspend_if_needed(interval);
20if (left_element[sort_on] > right_element[sort_on])
21merged_list = {left_element, @merged_list};
22if (left_index = left_index - 1)
23left_element = left_sublist[left_index];
24else
25return {@right_sublist[1..right_index], @merged_list};
26endif
27else
28merged_list = {right_element, @merged_list};
29if (right_index = right_index - 1)
30right_element = right_sublist[right_index];
31else
32return {@left_sublist[1..left_index], @merged_list};
33endif
34endif
35endwhile

randomly_permute randomize

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1":randomly_permute(list) => list with its elements randomly permuted";
2"  each of the length(list)! possible permutations is equally likely";
3plist = {};
4for i in [1..length(ulist = args[1])]
5plist = listinsert(plist, ulist[i], random(i));
6endfor
7return plist;

count

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

none

Source

1"$list_utils:count(item, list)";
2"Returns the number of occurrences of item in list.";
3{x, xlist} = args;
4if (typeof(xlist) != LIST)
5return E_INVARG;
6endif
7counter = 0;
8while (loc = x in xlist)
9counter = counter + 1;
10xlist = xlist[loc + 1..$];
11endwhile
12return counter;

flatten flatten_suspended

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1":flatten(LIST list_of_lists) => LIST of all lists in given list `flattened'";
2newlist = {};
3for elm in (args[1])
4if (typeof(elm) == LIST)
5newlist = {@newlist, @this:flatten(elm)};
6else
7newlist = {@newlist, elm};
8endif
9(verb[$] == "d") && $cu:sin();
10endfor
11return newlist;

longest shortest

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1"Copied from APHiD (#33119):longest Sun May  9 21:00:18 1993 PDT";
2"$list_utils:longest(<list>)";
3"$list_utils:shortest(<list>)";
4"             - Returns the shortest or longest element in the list.  Elements may be either strings or lists.  Returns E_TYPE if passed a non-list or a list containing non-string/list elements.  Returns E_RANGE if passed an empty list.";
5if (typeof(all = args[1]) != LIST)
6return E_TYPE;
7elseif (all == {})
8return E_RANGE;
9else
10result = all[1];
11for things in (all)
12if ((typeof(things) != LIST) && (typeof(things) != STR))
13return E_TYPE;
14else
15result = (((verb == "longest") && (length(result) < length(things))) || ((verb == "shortest") && (length(result) > length(things)))) ? things | result;
16endif
17endfor
18endif
19return result;

check_nonstring_tell_lines

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

none

Source

1"check_nonstring_tell_lines(lines)";
2if (caller_perms().wizard)
3"don't let a nonwizard mess up our stats";
4for line in (args[1])
5if (typeof(line) != STR)
6this.nonstring_tell_lines = listappend(this.nonstring_tell_lines, callers());
7return;
8endif
9endfor
10endif

reverse_suspended

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1"reverse(list) => reversed list.  Does suspend(0) as necessary.";
2set_task_perms(caller_perms());
3"^^^For suspend task.";
4return this:_reverse_suspended(@args[1]);

_reverse_suspended

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1":_reverse(@list) => reversed list";
2set_task_perms(caller_perms());
3$command_utils:suspend_if_needed(0);
4if (length(args) > 50)
5return {@this:_reverse_suspended(@args[($ / 2) + 1..$]), @this:_reverse_suspended(@args[1..$ / 2])};
6endif
7l = {};
8for a in (args)
9l = listinsert(l, a);
10endfor
11return l;

randomly_permute_suspended

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

none

Source

1":randomly_permute_suspended(list) => list with its elements randomly permuted";
2"  each of the length(list)! possible permutations is equally likely";
3set_task_perms(caller_perms());
4plist = {};
5for i in [1..length(ulist = args[1])]
6plist = listinsert(plist, ulist[i], random(i));
7yield;
8endfor
9return plist;

swap_elements

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1"swap_elements -- exchange two elements in a list";
2"Usage:  $list_utils:swap_elements(<list/LIST>,<index/INT>,<index/INT>)";
3"        $list_utils:swap_elements({\"a\",\"b\"},1,2);";
4{l, i, j} = args;
5if (((typeof(l) == LIST) && (typeof(i) == INT)) && (typeof(j) == INT))
6ll = length(l);
7if (((i > 0) && (i <= ll)) && ((j > 0) && (j <= ll)))
8t = l[i];
9l[i] = l[j];
10l[j] = t;
11return l;
12else
13return E_RANGE;
14endif
15else
16return E_TYPE;
17endif

random_item random_element

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

none

Source

1"random_item -- returns a random element of the input list.";
2if (length(args) == 1)
3if (typeof(l = args[1]) == LIST)
4if (length(l) > 0)
5return l[random($)];
6else
7return E_RANGE;
8endif
9else
10return E_TYPE;
11endif
12else
13return E_ARGS;
14endif

assoc_suspended

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

none

Source

1"Copied from Moo_tilities (#332):assoc_suspended by Mooshie (#106469) Wed Mar 18 19:27:54 1998 PST";
2"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.  Index defaults to 1.";
3"Returns {} if no such element is found.";
4"Suspends as necessary. Suspend length defaults to 0.";
5set_task_perms(caller_perms());
6{target, thelist, ?indx = 1, ?suspend_for = 0} = args;
7cu = $command_utils;
8for t in (thelist)
9if (`t[indx] == target ! E_TYPE => 0')
10if ((typeof(t) == LIST) && (length(t) >= indx))
11return t;
12endif
13endif
14cu:suspend_if_needed(suspend_for);
15endfor
16return {};

amerge

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

none

Source

1"Copied from Uther's_Ghost (#93141):amerge Tue May 27 20:28:18 1997 PDT";
2"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. Useful for merging alists ( amerge({@alist1, @alist2, ...}) ) and for ensuring that each tuple has a unique index. Tindex defaults to 1. Dindex defaults to 1 and refers to the position in the tuple where the tindex-th element will land in the new tuple.";
3{alist, ?tidx = 1, ?didx = 1} = args;
4if (alist)
5alist = this:sort_alist(alist, tidx);
6i = 1;
7res = {{cur = alist[1][tidx]}};
8for tuple in (alist)
9if (tuple[tidx] == cur)
10res[i] = {@res[i], @listdelete(tuple, tidx)};
11else
12if (didx != 1)
13res[i] = this:swap_elements(res[i], 1, min(didx, length(res[i])));
14endif
15i = i + 1;
16res = {@res, {cur = tuple[tidx], @listdelete(tuple, tidx)}};
17endif
18endfor
19return res;
20endif
21return alist;

passoc

Spec this none thisFlags rxOwner #29Definer #47

Referenced by

none

Source

1"passoc(key,list1,list2)";
2"passoc() behaves rather similarly to assoc, with the exception that it's intended for";
3"parallel lists.  given a key from list1, it returns a list containing the key and the";
4"corresponding item from list2 (\"corresponding\", in the case of parallel lists, means";
5"having the same index.)";
6indx = args[1] in args[2];
7if (indx)
8return {args[1], args[3][indx]};
9else
10return {};
11endif

setmove

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

none

Source

1"Copied from Moo_tilities (#332):setmove by Mooshie (#106469) Mon Sep 22 21:07:25 1997 PDT";
2"Usage: setmove(LIST elements, INT from, INT to)";
3"Moves element in list from one position in list to another.";
4"";
5"Example: setmove({x, y, z}, 1, 3) => {y, z, x}";
6"         setmove({x, y, z}, 2, 1} => {y, x, z}";
7{start, from, to} = args;
8what = start[from];
9return listinsert(listdelete(start, from), what, to);
10"  Written by Mooshie (#106469) @ Lambda - Mon Sep 22 21:03:26 1997 PDT -  ";

iassoc_new

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

none

Source

1"Copied from Moo_tilities (#332):iassoc_new by Mooshie (#106469) Wed Mar 18 19:27:52 1998 PST";
2"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.  Index defaults to 1.";
3"Returns 0 if no such element is found.";
4"NOTE: expects that each index in the given list will be a list with at least as many elements as the indicated `index' argument. Otherwise will return E_RANGE";
5{target, thelist, ?indx = 1} = args;
6try
7for element in (thelist)
8if (element[indx] == target)
9if (typeof(element) == LIST)
10return element in thelist;
11endif
12endif
13endfor
14except e (ANY)
15return e[1];
16endtry
17return 0;

build_alist

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

none

Source

1"Syntax:  build_alist(list, N) =>";
2"{list[1..N], list[N+1..N*2], list[N*2+1..N*3], ..., list[N*(N-1)+1..N*N]}";
3"";
4"Creates an associated list from a flat list at every Nth interval. If the list doesn't have a multiple of N elements, E_RANGE is returned.";
5"Example:  build_alist({a,b,c,d,e,f,g,h,i},3)=>{{a,b,c},{d,e,f},{g,h,i}}";
6{olist, interval} = args;
7if ((tot = length(olist)) % interval)
8return E_RANGE;
9endif
10nlist = {};
11d = 1;
12while (d <= tot)
13nlist = {@nlist, olist[1..interval]};
14olist[1..interval] = {};
15d = d + interval;
16endwhile
17return nlist;

sort_value

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

none

Source

1"Copied from list utilities (#55):sort by Hacker (#36) Thu Apr 28 23:26:51 2005 PDT";
2"sort(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.";
3"sort({x1,x3,x2},{1,3,2}) => {x1,x2,x3}";
4lst = args[1];
5unsorted_keys = (use_sorted_lst = length(args) >= 2) ? args[2] | lst;
6sorted_lst = sorted_keys = {};
7for e in (unsorted_keys)
8l = this:find_insert_value(sorted_keys, e);
9sorted_keys = listinsert(sorted_keys, e, l);
10endfor
11return sorted_lst || sorted_keys;

find_insert_value

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1"Copied from list utilities (#55):find_insert by Hacker (#36) Thu Apr 28 23:29:10 2005 PDT";
2"find_insert(sortedlist,key) => index of first element in sortedlist > key";
3"  sortedlist is assumed to be sorted in increasing order and the number returned is anywhere from 1 to length(sortedlist)+1, inclusive.";
4{lst, key} = args;
5if ((r = length(lst)) < 25)
6for l in [1..r]
7if (lst[l].value > key.value)
8return l;
9endif
10endfor
11return r + 1;
12else
13l = 1;
14while (r >= l)
15if (key.value < lst[i = (r + l) / 2].value)
16r = i - 1;
17else
18l = i + 1;
19endif
20endwhile
21return l;
22endif

sort_prop

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1lst = args[1];
2prop = args[2];
3unsorted_keys = lst;
4sorted_lst = sorted_keys = {};
5for e in (unsorted_keys)
6l = this:find_insert_prop(sorted_keys, e, prop);
7sorted_keys = listinsert(sorted_keys, e, l);
8endfor
9return sorted_lst || sorted_keys;

find_insert_prop

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1{lst, key, prop} = args;
2if ((r = length(lst)) < 25)
3for l in [1..r]
4if (lst[l].(prop) > key.(prop))
5return l;
6endif
7endfor
8return r + 1;
9else
10l = 1;
11while (r >= l)
12if (key.(prop) < lst[i = (r + l) / 2].(prop))
13r = i - 1;
14else
15l = i + 1;
16endif
17endwhile
18return l;
19endif

map_verb_value

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1"Copied from list utilities (#55):map_verb by Satan (#2) Mon Dec  5 01:49:37 2005 CST";
2set_task_perms(caller_perms());
3{objs, vrb, @rest} = args;
4if (length(objs) > 50)
5return {@this:map_verb(@listset(args, objs[1..$ / 2], 1)), @this:map_verb(@listset(args, objs[($ / 2) + 1..$], 1))};
6endif
7strs = {};
8for o in (objs)
9strs = {@strs, tostr(o:(vrb)(@rest))};
10endfor
11return strs;

amerge_suspended

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

none

Source

1"Copied from list utilities (#55):amerge by Hacker (#36) Mon Jul 23 23:32:48 2007 CDT";
2"Copied from Uther's_Ghost (#93141):amerge Tue May 27 20:28:18 1997 PDT";
3"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. Useful for merging alists ( amerge({@alist1, @alist2, ...}) ) and for ensuring that each tuple has a unique index. Tindex defaults to 1. Dindex defaults to 1 and refers to the position in the tuple where the tindex-th element will land in the new tuple.";
4{alist, ?tidx = 1, ?didx = 1} = args;
5if (alist)
6alist = this:sort_alist_suspended(0, alist, tidx);
7i = 1;
8res = {{cur = alist[1][tidx]}};
9for tuple in (alist)
10if (tuple[tidx] == cur)
11res[i] = {@res[i], @listdelete(tuple, tidx)};
12else
13if (didx != 1)
14res[i] = this:swap_elements(res[i], 1, min(didx, length(res[i])));
15endif
16i = i + 1;
17res = {@res, {cur = tuple[tidx], @listdelete(tuple, tidx)}};
18endif
19$cu:sin(0);
20endfor
21return res;
22endif
23return alist;

setremove_all_list

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

none

Source

1":setremove_all(set,elt) => set with *all* occurences of elt removed";
2{set, things} = args;
3for thing in (things)
4while (w = thing in set)
5set = listdelete(set, w);
6endwhile
7endfor
8return set;

list_is_a is_a

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1is = {};
2for x in (args[1])
3if (is_a(x, args[2]))
4is = listappend(is, x);
5endif
6endfor
7return is;

sort_cardinal

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

none

Source

1exits = args[1];
2cardinals = others = {};
3for exit in (exits)
4if (!is_a(exit, $exit))
5continue;
6endif
7if (exit.direction in $rpg.cardinals)
8cardinals = setadd(cardinals, exit);
9else
10others = setadd(others, exit);
11endif
12endfor
13others = this:sort_prop(others, "name");
14unsorted_keys = unsorted_list = cardinals;
15sorted_keys = sorted_list = {};
16for e in (unsorted_keys)
17l = this:find_insert_cardinal(sorted_keys, e);
18sorted_keys = listinsert(sorted_keys, e, l);
19endfor
20return {@sorted_list || sorted_keys, @others};

find_insert_cardinal

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1"find_insert(sortedlist,key) => index of first element in sortedlist > key";
2"  sortedlist is assumed to be sorted in increasing order and the number returned is anywhere from 1 to length(sortedlist)+1, inclusive.";
3{lst, key} = args;
4if ((r = length(lst)) < 25)
5for l in [1..r]
6if (((lst[l].direction in $rpg.cardinals) == (key.direction in $rpg.cardinals)) && (strcmp(lst[l].name, key.name) < 0))
7return l;
8elseif ((lst[l].direction in $rpg.cardinals) > (key.direction in $rpg.cardinals))
9return l;
10endif
11endfor
12return r + 1;
13else
14l = 1;
15while (r >= l)
16if ((key.direction in $rpg.cardinals) < (lst[i = (r + l) / 2].direction in $rpg.cardinals))
17r = i - 1;
18else
19l = i + 1;
20endif
21endwhile
22return l;
23endif

same_sets

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1":same_sets(LIST set1, LIST set2) => Is every member of set1 in set2 and vice versa?";
2set1 = args[1];
3set2 = args[2];
4for x in (set1)
5if (set2 != (s = setremove(set2, x)))
6set2 = s;
7else
8return 0;
9endif
10endfor
11if (set2)
12return 0;
13endif
14return 1;

sort_cardinal_suspended

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1exits = args[1];
2cardinals = others = {};
3for exit in (exits)
4if (!is_a(exit, $exit))
5continue;
6endif
7if (exit.direction in $rpg.cardinals)
8cardinals = setadd(cardinals, exit);
9else
10others = setadd(others, exit);
11endif
12endfor
13others = this:sort_prop(others, "name");
14unsorted_keys = unsorted_list = cardinals;
15sorted_keys = sorted_list = {};
16for e in (unsorted_keys)
17l = this:find_insert_cardinal(sorted_keys, e);
18sorted_keys = listinsert(sorted_keys, e, l);
19$cu:sin();
20endfor
21return {@sorted_list || sorted_keys, @others};

random

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1l = args[1];
2if (!l)
3raise(E_INVARG);
4endif
5return l[random(length(l))];

count_list

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

none

Source

1":count_list(LIST l) => { {ANY a, INT count_of_a}, {ANY b, INT count_of_b}, ... }";
2"    Given a list, $lu:count_list(list) will return an associative list of the list's items and how many times they occured.";
3"    Example: $lu:count_list({'a', 'a', 'b', 'b', 'c'}) => { {'a', 2}, {'b', 2}, {'c', 1} }";
4{sourcelist} = args;
5assoc = {};
6for x in (sourcelist)
7idx = this:iassoc(x, assoc);
8if (idx)
9assoc[idx][2] = assoc[idx][2] + 1;
10else
11assoc = listappend(assoc, {x, 1});
12endif
13endfor
14return assoc;

count_list_suspended

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

none

Source

1":count_list_suspended(LIST l, INT suspend) => { {ANY a, INT count_of_a}, {ANY b, INT count_of_b}, ... }";
2" Like count_list but for huge things. suspend defaults to 1.";
3{sourcelist, ?suspend = 1} = args;
4assoc = {};
5for x in (sourcelist)
6idx = this:iassoc(x, assoc);
7if (idx)
8assoc[idx][2] = assoc[idx][2] + 1;
9else
10assoc = {@assoc, {x, 1}};
11endif
12yield suspend;
13endfor
14return assoc;

group_objects

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

none

Source

1":group_objects(LIST objects, LIST type1parents, LIST type2parents, ..., LIST typeNparents)";
2" => {LIST type1objs, LIST type2objs, ..., LIST typeNobjs, LIST unclassified_objs}";
3if (length(args) < 2)
4raise(E_ARGS);
5endif
6objs = args[1];
7types = args[2..$];
8ntypes = length(types);
9groups = $lu:make(ntypes + 1, {});
10for o in (objs)
11for type_idx in [1..ntypes]
12for p in (types[type_idx])
13if (is_a(o, p))
14groups[type_idx] = {@groups[type_idx], o};
15continue o;
16endif
17endfor
18endfor
19groups[$] = {@groups[$], o};
20$cu:sin();
21endfor
22return groups;

as_list

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1"$list_utils:as_list(variable)";
2"If the variable is not already a list, make it into one, otherwise return the original value.";
3v = args[1];
4if (typeof(v) == LIST)
5return v;
6endif
7return {v};

sum

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1":sum(list) => INT sum of all elements";
2total = 0;
3for x in (args[1])
4total = total + x;
5endfor
6return total;

foldl

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

none

Source

1":foldl(o, f, start, list) => Do a left-fold of 'o:f' across 'list'.";
2{o, f, acc, LIST} = args;
3while (LIST)
4acc = o:(f)(acc, LIST[1]);
5LIST = listdelete(LIST, 1);
6endwhile
7return acc;

remove_if remove_if_not remove_if_suspended remove_if_not_suspended

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1":remove_if/remove_if_not/remove_if_suspended/remove_if_not_suspended(o, v, l[, @args]) => Remove all elements e from 'l' for which the call o:v(e, @args) returns true.  If remove_if_not, remove those for which the call returns false.  The _suspended version will use $cu:sin.";
2{o, v, l, @rest} = args;
3n = length(l);
4i = 1;
5x = (length(verb) > 10) && (verb[11] == "n");
6suspend = verb[$] == "d";
7while (i <= n)
8if (((!(!o:(v)(l[i], @rest))) + x) == 1)
9l = listdelete(l, i);
10n = n - 1;
11else
12i = i + 1;
13endif
14if (suspend)
15$cu:sin();
16endif
17endwhile
18return l;

tolist

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

none

Source

1return args;

make_alist

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1":make_alist(lists[, pad])";
2"Make an alist out of n parallel lists (basically a matrix transpose).";
3"If the lists are of uneven length, fill the remaining tuples with pad (defaults to 0).";
4alist = {};
5pad = (length(args) > 1) ? args[2] | 0;
6max_len = max(@$lu:map_args($bf, "length", args[1]));
7for i in [1..max_len]
8tuple = {};
9for l in (args[1])
10tuple = {@tuple, (i > length(l)) ? pad | l[i]};
11endfor
12alist = {@alist, tuple};
13endfor
14return alist;

break_at

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

none

Source

1":break_at(LIST l, INT n) => {LIST a, LIST b, ...}";
2"break list l into chunks of max length n.";
3{l, n} = args;
4result = {};
5full_chunks = length(l) / n;
6extra_chunk = length(l) % n;
7for i in [1..full_chunks]
8result = {@result, l[1 + (n * (i - 1))..n * i]};
9endfor
10if (extra_chunk)
11result = {@result, l[$ - (extra_chunk - 1)..$]};
12endif
13return result;

is_one_of

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1{what, cand} = args;
2is = {};
3for c in (cand)
4if (is_a(what, c))
5is = {@is, c};
6endif
7endfor
8return is;

sort_callback

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

none

Source

1{lst, callback} = args;
2"Just to validate the callback...";
3{verbtarget, verbname} = callback;
4unsorted_keys = lst;
5sorted_lst = sorted_keys = {};
6for e in (unsorted_keys)
7l = this:_find_insert_callback(sorted_keys, e, callback);
8sorted_keys = listinsert(sorted_keys, e, l);
9endfor
10return sorted_lst || sorted_keys;

_find_insert_callback

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

Source

1{lst, key, callback} = args;
2{target, verbname} = callback;
3if ((r = length(lst)) < 25)
4for l in [1..r]
5if (target:(verbname)(lst[1], key) > 0)
6return l;
7endif
8endfor
9return r + 1;
10else
11l = 1;
12while (r >= l)
13if (target:(verbname)(key, lst[i = (r + l) / 2]) < 0)
14r = i - 1;
15else
16l = i + 1;
17endif
18endwhile
19return l;
20endif

are

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

none

Source

1{what, cand} = args;
2is = {};
3for bob in (what)
4for fag in (cand)
5if (is_a(bob, fag))
6is = {@is, bob};
7break;
8endif
9endfor
10endfor
11return is;

valid gamevalid

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

none

Source

1{apples} = args;
2oranges = {};
3for apple in (apples)
4if ((verb == "gamevalid") ? gamevalid(apple) | valid(apple))
5oranges = {@oranges, apple};
6endif
7endfor
8return oranges;

implode

Spec this none thisFlags rxdOwner #361Definer #47

Referenced by

Source

1"Return a string from a list with a given delimiter (default a space) as args[2]";
2{what, ?delimiter = " "} = args;
3string = "";
4curlen = 1;
5maxlen = length(what);
6for li in (what)
7string = (string + li) + ((curlen < maxlen) ? delimiter | "");
8curlen = curlen + 1;
9endfor
10return string;

sort_prop_suspended

Spec this none thisFlags rxdOwner #29Definer #47

Referenced by

none

Source

1"Copied from list utilities (#55):sort_prop by Hacker (#36) Tue Apr  5 23:04:35 2011 PDT";
2{lst, prop, ?interval = 1} = args;
3unsorted_keys = lst;
4sorted_lst = sorted_keys = {};
5for e in (unsorted_keys)
6l = this:find_insert_prop(sorted_keys, e, prop);
7sorted_keys = listinsert(sorted_keys, e, l);
8yield interval;
9endfor
10return sorted_lst || sorted_keys;