list utilities #55
Aliases: list utilities, list_utilities
38 verbs · 7 properties · 0 children
Verbs
| Verb | Spec | Flags | Definer | Lines |
|---|---|---|---|---|
make | this none this | rxd | #55 | 17 |
range | this none this | rxd | #55 | 7 |
map_prop*erty | this none this | rxd | #55 | 10 |
map_verb | this none this | rxd | #55 | 10 |
map_arg | this none this | rxd | #55 | 16 |
map_builtin | this none this | rxd | #55 | 14 |
find_insert | this none this | rxd | #55 | 21 |
remove_duplicates | this none this | rxd | #55 | 6 |
arrayset | this none this | rxd | #55 | 8 |
setremove_all | this none this | rxd | #55 | 6 |
append | this none this | rxd | #55 | 9 |
reverse | this none this | rxd | #55 | 2 |
_reverse | this none this | rxd | #55 | 9 |
compress | this none this | rxd | #55 | 14 |
sort | this none this | rxd | #55 | 13 |
sort_suspended | this none this | rxd | #55 | 19 |
slice | this none this | rxd | #55 | 20 |
assoc | this none this | rxd | #55 | 11 |
iassoc | this none this | rxd | #55 | 13 |
iassoc_suspended | this none this | rxd | #55 | 16 |
assoc_prefix | this none this | rxd | #55 | 8 |
iassoc_prefix | this none this | rxd | #55 | 8 |
iassoc_sorted | this none this | rxd | #55 | 22 |
sort_alist | this none this | rxd | #55 | 57 |
sort_alist_suspended | this none this | rxd | #55 | 35 |
randomly_permute | this none this | rxd | #55 | 7 |
count | this none this | rxd | #55 | 12 |
flatten | this none this | rxd | #55 | 11 |
longest shortest | this none this | rxd | #55 | 19 |
check_nonstring_tell_lines | this none this | rxd | #55 | 10 |
reverse_suspended | this none this | rxd | #55 | 4 |
_reverse_suspended | this none this | rxd | #55 | 11 |
randomly_permute_suspended | this none this | rxd | #55 | 9 |
swap_elements | this none this | rxd | #55 | 17 |
random_item random_element | this none this | rxd | #55 | 14 |
assoc_suspended | this none this | rxd | #55 | 13 |
amerge | this none this | rxd | #55 | 20 |
build_alist | this none this | rxd | #55 | 17 |
Properties
| Property | Definer | Flags | Owner | Value |
|---|---|---|---|---|
nonstring_tell_lines | #55 | r | #36 | {} |
help_msg | #79 | rc | #36 | list of 45{"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"} |
key | #1 | c | #36 | <clear> |
aliases | #1 | rc | #36 | {"list utilities", "list_utilities"} |
description | #1 | rc | #36 | {"This is the list utilities utility package. See `help $list_utils' for more details."} |
object_size | #1 | r | #36 | {26955, -1090650497} |
html | #1 | rc | #36 | <clear> |
Ancestry
Ancestors (nearest first): #79 Generic Utilities Package → #1 Root Class
Children: none
Call graph
Source
make
Referenced by
- #14:_repair line 47:
$list_utils:make - #20:columnize line 4:
$list_utils:make - #20:columnize_suspended line 4:
$list_utils:make - #30:sort_topics line 3:
$list_utils:make - #32:columnize line 6:
$list_utils:make - #46:parse_misc_headers line 14:
$list_utils:make - #59:_fix_preps line 23:
$list_utils:make - #60:wizard_list line 9:
$list_utils:make - #90:add_refusal line 32:
$list_utils:make
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
Referenced by
- #45:date_sort line 8:
$list_utils:range - #128:generate_weather line 4:
$list_utils:range
Source
1":range([m,]n) => {m,m+1,...,n}"; 2{?m = 1, n} = args; 3ret = {}; 4for k in [m..n] 5ret = {@ret, k}; 6endfor 7return ret;
map_prop*erty
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
Referenced by
- #20:title_list*c line 4:
$list_utils:map_verb - #55:map_verb line 4:
this:map_verb - #55:map_verb line 4:
this:map_verb
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
Referenced by
- #6:@listgag line 5:
$list_utils:map_arg - #6:@listgag line 17:
$list_utils:map_arg - #6:@addalias*# line 79:
$list_utils:map_arg - #6:@rmalias*# line 69:
$list_utils:map_arg - #14:from_msg_seq line 27:
$list_utils:map_arg - #14:%from_msg_seq line 29:
$list_utils:map_arg - #14:to_msg_seq line 28:
$list_utils:map_arg - #14:%to_msg_seq line 29:
$list_utils:map_arg - #14:_repair line 115:
$list_utils:map_arg - #21:parse_names line 11:
$list_utils:map_arg - #29:from_msg_seq line 24:
$list_utils:map_arg - #30:index line 6:
$list_utils:map_arg - #33:intersection line 8:
$list_utils:map_arg - #40:notify_mail line 15:
$list_utils:map_arg - #40:notify_mail line 22:
$list_utils:map_arg - #40:@unsub*scribe line 43:
$list_utils:map_arg - #46:match_failed line 9:
$list_utils:map_arg - #46:name_list line 1:
$list_utils:map_arg - #46:from_msg_seq line 23:
$list_utils:map_arg - #46:%from_msg_seq line 25:
$list_utils:map_arg - #46:to_msg_seq line 24:
$list_utils:map_arg - #46:%to_msg_seq line 25:
$list_utils:map_arg - #47:subsc*ribe line 25:
$list_utils:map_arg - #47:unsubsc*ribe line 23:
$list_utils:map_arg - #56:player_match_result line 38:
$list_utils:map_arg
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()); 5if (n = args[1]) 6{object, verb, @rest} = args[2..$]; 7else 8object = n; 9n = 1; 10{verb, @rest} = args[2..$]; 11endif 12results = {}; 13for a in (rest[n]) 14results = listappend(results, object:(verb)(@listset(rest, a, n))); 15endfor 16return results;
map_builtin
Referenced by
- #55:map_builtin line 8:
this:map_builtin - #55:map_builtin line 8:
this:map_builtin - #96:ansi_log line 4:
$list_utils:map_builtin
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
Referenced by
- #20:subst*itute line 17:
$list_utils:find_insert - #20:subst*itute line 39:
$list_utils:find_insert - #20:substitute_d*elimited line 13:
$list_utils:find_insert - #20:substitute_d*elimited line 35:
$list_utils:find_insert - #30:sort_topics line 8:
$list_utils:find_insert - #33:add line 7:
$list_utils:find_insert - #33:add line 11:
$list_utils:find_insert - #33:contains line 2:
$list_utils:find_insert - #33:extract line 4:
$list_utils:find_insert - #33:extract line 5:
$list_utils:find_insert - #33:expand line 21:
$list_utils:find_insert - #33:contract line 19:
$list_utils:find_insert - #33:_union line 55:
$list_utils:find_insert - #33:_union line 87:
$list_utils:find_insert - #40:mail_catch_up line 18:
$list_utils:find_insert - #55:sort line 7:
this:find_insert - #55:sort_suspended line 12:
this:find_insert
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
Referenced by
- #6:@addalias*# line 47:
$list_utils:remove_duplicates - #6:@addalias*# line 79:
$list_utils:remove_duplicates - #6:@rmalias*# line 33:
$list_utils:remove_duplicates - #6:@rmalias*# line 69:
$list_utils:remove_duplicates - #37:_every line 6:
$list_utils:remove_duplicates - #51:object_match_failed line 23:
$list_utils:remove_duplicates - #71:clean_status line 10:
$list_utils:remove_duplicates - #71:fix_all_exits line 10:
$list_utils:remove_duplicates - #71:exit_alias_builder line 67:
$list_utils:remove_duplicates - #71:find_duplicate_verbs line 9:
$list_utils:remove_duplicates - #90:find_verb line 4:
$list_utils:remove_duplicates - #90:find_property line 4:
$list_utils:remove_duplicates - #91:short_desc_matches line 7:
$list_utils:remove_duplicates - #91:short_desc_matches line 10:
$list_utils:remove_duplicates - #118:add_virtual_exit line 3:
$list_utils:remove_duplicates - #118:con*vert-exit line 34:
$list_utils:remove_duplicates - #134:items line 7:
$list_utils:remove_duplicates
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
Referenced by
- #55:arrayset line 4:
this:arrayset
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
Referenced by
- #33:union line 3:
$list_utils:setremove_all - #33:intersection line 3:
$list_utils:setremove_all - #43:parse_english_time_interval line 14:
$list_utils:setremove_all
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
Referenced by
- #30:sort_topics line 13:
$list_utils:append - #55:append line 3:
this:append - #55:append line 3:
this:append - #98:mass_heal line 9:
$list_utils:append - #104:@fakes line 8:
$list_utils:append
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
Referenced by
- #24:check_player_request line 48:
$list_utils:reverse - #40:mail_catch_up line 26:
$list_utils:reverse - #80:do_breakdown line 22:
$list_utils:reverse - #80:do_breakdown line 43:
$list_utils:reverse - #84:list line 11:
$list_utils:reverse
Source
1"reverse(list) => reversed list"; 2return this:_reverse(@args[1]);
_reverse
Referenced by
- #55:reverse line 2:
this:_reverse - #55:_reverse line 3:
this:_reverse - #55:_reverse line 3:
this:_reverse
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
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
Referenced by
- #0:core_objects line 15:
$list_utils:sort - #24:boot_idlers line 34:
$list_utils:sort - #33:from_list line 2:
$list_utils:sort - #45:date_sort line 8:
$list_utils:sort - #55:sort_alist line 5:
this:sort - #55:sort_alist_suspended line 8:
this:sort - #83:help_msg line 17:
$list_utils:sort - #90:do_at_all line 16:
$list_utils:sort - #90:do_at_all line 17:
$list_utils:sort
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) 7l = this:find_insert(sorted_keys, e); 8sorted_keys = listinsert(sorted_keys, e, l); 9if (use_sorted_lst) 10sorted_lst = listinsert(sorted_lst, lst[length(sorted_keys)], l); 11endif 12endfor 13return sorted_lst || sorted_keys;
sort_suspended
Referenced by
- #4:@sort-owned*-objects line 8:
$list_utils:sort_suspended - #4:@sort-owned*-objects line 10:
$list_utils:sort_suspended - #4:classes_2 line 10:
$list_utils:sort_suspended - #6:@users line 4:
$list_utils:sort_suspended - #24:show_missing_help line 12:
$list_utils:sort_suspended - #63:look_self line 7:
$list_utils:sort_suspended - #80:do_breakdown line 22:
$list_utils:sort_suspended - #80:do_breakdown line 43:
$list_utils:sort_suspended
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(ticks_left() < 4000) && suspend(interval); 18endfor 19return sorted_lst || sorted_keys;
slice
Referenced by
- #4:@sort-owned*-objects line 10:
$list_utils:slice - #14:_repair line 115:
$list_utils:slice - #40:@subscribe*-quick line 17:
$list_utils:slice - #46:msg_seq_to_msg_num_string line 3:
$list_utils:slice - #46:msg_seq_to_msg_num_list line 3:
$list_utils:slice - #55:sort_alist line 5:
this:slice - #55:sort_alist_suspended line 8:
this:slice - #57:@blacklist line 77:
$list_utils:slice - #57:@blacklist line 84:
$list_utils:slice - #59:task_valid line 5:
$list_utils:slice - #59:callers_text line 8:
lu:slice - #62:enterfunc line 7:
$list_utils:slice - #68:set line 39:
$list_utils:slice - #68:parsechoice line 5:
$list_utils:slice - #80:do_breakdown line 22:
$list_utils:slice - #80:do_breakdown line 43:
$list_utils:slice - #90:whois line 20:
$list_utils:slice - #91:die line 54:
$list_utils:slice - #91:tell line 11:
$list_utils:slice - #91:title line 1:
$list_utils:slice - #91:title line 2:
$list_utils:slice - #91:_add_money line 4:
$list_utils:slice - #91:_has_amount line 2:
$list_utils:slice - #91:remember line 7:
$list_utils:slice - #93:matrix_add line 10:
$list_utils:slice - #93:matrix_add line 14:
$list_utils:slice - #96:ansi_log line 4:
$list_utils:slice - #98:welfare line 12:
$list_utils:slice - #99:atrun line 6:
$list_utils:slice - #102:ansi_title line 1:
$list_utils:slice - #103:_has_currency line 2:
$list_utils:slice - #103:_from_to line 8:
$list_utils:slice - #103:_from_to line 8:
$list_utils:slice - #103:match_org line 5:
$list_utils:slice - #103:match_org line 6:
$list_utils:slice - #104:@fakes line 7:
$list_utils:slice - #104:queue_attack line 8:
$list_utils:slice - #104:queue_attack line 12:
$list_utils:slice - #104:title line 1:
$list_utils:slice - #107:wander line 60:
$list_utils:slice - #107:wander line 62:
$list_utils:slice - #109:title line 3:
$list_utils:slice - #115:g*et line 7:
$list_utils:slice - #116:ask line 79:
$list_utils:slice - #123:help_msg line 3:
$list_utils:slice - #129:learn line 22:
$list_utils:slice - #129:learn line 39:
$list_utils:slice - #129:learn line 53:
$list_utils:slice - #129:match_lang line 6:
$list_utils:slice - #133:join line 1:
$list_utils:slice - #133:add_donor line 2:
$list_utils:slice - #133:rem_donor line 2:
$list_utils:slice - #133:donor_tally line 2:
$list_utils:slice - #138:group_booguns line 6:
$list_utils:slice - #138:group_booguns line 16:
$list_utils:slice - #141:set_stats line 3:
$list_utils:slice - #141:pick_race line 37:
$list_utils:slice - #141:pick_race line 45:
$list_utils:slice - #141:pick_race line 51:
$list_utils:slice - #141:limit_check line 6:
$list_utils:slice - #141:limit_check line 12:
$list_utils:slice - #141:limit_check line 28:
$list_utils:slice - #141:limit_check line 41:
$list_utils:slice - #141:pick_org line 34:
$list_utils:slice - #141:pick_org line 51:
$list_utils:slice - #141:pick_org line 52:
$list_utils:slice - #143:pub_title line 2:
$list_utils:slice - #158:g*et line 7:
$list_utils:slice
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
Referenced by
- #6:init_for_core line 4:
$list_utils:assoc - #6:verb_sub line 2:
$list_utils:assoc - #10:co*nnect line 76:
$list_utils:assoc - #10:blacklist_remove*_temp line 10:
$list_utils:assoc - #10:blacklisted_temp line 11:
$list_utils:assoc - #10:blacklisted_temp line 13:
$list_utils:assoc - #12:last line 18:
$list_utils:assoc - #24:check_prog_restricted line 7:
$list_utils:assoc - #40:current_message line 10:
$list_utils:assoc - #40:get_current_message line 12:
$list_utils:assoc - #43:from_ctime line 7:
$list_utils:assoc - #46:parse_message_seq line 28:
$list_utils:assoc - #50:commands_info line 2:
$list_utils:assoc - #57:mcd_2 line 50:
$list_utils:assoc - #57:@unnewt line 16:
$list_utils:assoc - #57:@blacklist line 81:
$list_utils:assoc - #57:@blacklist line 95:
$list_utils:assoc - #57:@blacklist line 137:
$list_utils:assoc - #58:eval_value_to_string line 3:
$list_utils:assoc - #59:task_owner line 2:
$list_utils:assoc - #59:owns_task line 3:
$list_utils:assoc - #68:get line 8:
$list_utils:assoc - #68:set line 38:
$list_utils:assoc - #68:show line 24:
$list_utils:assoc - #72:incoming_connection line 9:
$list_utils:assoc - #78:remove line 9:
$list_utils:assoc - #87:close line 6:
$list_utils:assoc - #87:controls line 1:
$list_utils:assoc - #87:close_data line 5:
$list_utils:assoc - #95:ansi_option line 3:
$list_utils:assoc - #95:@ansi-title line 40:
$list_utils:assoc
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 (`t[indx] == target ! E_TYPE => 0') 6if ((typeof(t) == LIST) && (length(t) >= indx)) 7return t; 8endif 9endif 10endfor 11return {};
iassoc
Referenced by
- #12:last line 29:
$list_utils:iassoc - #16:add line 9:
$list_utils:iassoc - #32:update_all line 33:
$list_utils:iassoc - #40:set_current_message line 14:
$list_utils:iassoc - #40:make_current_message line 16:
$list_utils:iassoc - #40:kill_current_message line 7:
$list_utils:iassoc - #40:@subscribe*-quick line 72:
$list_utils:iassoc - #40:make_current_message_new line 16:
$list_utils:iassoc - #46:raw_send line 33:
$list_utils:iassoc - #50:set_stateprops line 8:
$list_utils:iassoc - #57:@temp-newt line 18:
$list_utils:iassoc - #68:set line 59:
$list_utils:iassoc - #72:close line 9:
$list_utils:iassoc - #87:open line 11:
$list_utils:iassoc - #87:wait_for_response line 12:
$list_utils:iassoc - #87:get_messages line 5:
$list_utils:iassoc - #87:open_data line 5:
$list_utils:iassoc - #87:get_data line 5:
$list_utils:iassoc - #87:put_data line 5:
$list_utils:iassoc - #87:listen line 12:
$list_utils:iassoc - #87:data_connection line 3:
$list_utils:iassoc - #91:follow line 48:
$list_utils:iassoc - #91:do_forget line 3:
$list_utils:iassoc - #95:@ansi-title line 49:
$list_utils:iassoc - #99:assign line 1:
$list_utils:iassoc - #99:valid_task line 2:
$list_utils:iassoc
Source
1"iassoc(target,list[,index]) returns the index of the first element of `list' whose own index-th element is target. Index defaults to 1."; 2"returns 0 if no such element is found."; 3{target, thelist, ?indx = 1} = args; 4i = 1; 5for lsti in (thelist) 6if (`lsti[indx] == target ! E_TYPE => 0') 7if ((typeof(lsti) == LIST) && (length(lsti) >= indx)) 8return i; 9endif 10endif 11i = i + 1; 12endfor 13return 0;
iassoc_suspended
Referenced by
- #46:resolve_addr line 49:
$list_utils:iassoc_suspended
Source
1"iassoc_suspended(target,list[,index]) returns the index of the first element of `list' whose own index-th element is target. Index defaults to 1."; 2"returns 0 if no such element is found."; 3"suspends as needed."; 4set_task_perms(caller_perms()); 5{target, thelist, ?indx = 1} = args; 6i = 1; 7for lsti in (thelist) 8if (`lsti[indx] == target ! E_TYPE => 0') 9if ((typeof(lsti) == LIST) && (length(lsti) >= indx)) 10return i; 11endif 12endif 13i = i + 1; 14(ticks_left() < 4000) && suspend(1); 15endfor 16return 0;
assoc_prefix
Referenced by
- #4:@cl*asses line 11:
$list_utils:assoc_prefix
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
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
Referenced by
- #40:mail_catch_up line 22:
$list_utils:iassoc_sorted - #46:renumber line 10:
$list_utils:iassoc_sorted - #46:length_num_le line 3:
$list_utils:iassoc_sorted - #46:exists_num_eq line 3:
$list_utils:iassoc_sorted
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
Referenced by
- #32:show_who_listing line 33:
$list_utils:sort_alist - #32:show_who_listing line 34:
$list_utils:sort_alist - #55:sort_alist line 9:
this:sort_alist - #55:sort_alist line 10:
this:sort_alist - #55:amerge line 4:
this:sort_alist - #59:show_who_listing line 42:
$list_utils:sort_alist - #59:show_who_listing line 43:
$list_utils:sort_alist
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
Referenced by
- #24:show_netwho_listing line 45:
$list_utils:sort_alist_suspended - #55:sort_alist_suspended line 13:
this:sort_alist_suspended - #55:sort_alist_suspended line 14:
this:sort_alist_suspended - #57:@guests line 42:
$list_utils:sort_alist_suspended
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(ticks_left() < 4000) && suspend(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(ticks_left() < 4000) && suspend(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
Referenced by
- #60:wizard_list line 7:
$list_utils:randomly_permute
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
Referenced by
- #104:queue_attack line 8:
$list_utils:count - #104:queue_attack line 12:
$list_utils:count
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
Referenced by
- #55:flatten line 6:
this:flatten
Source
1"Copied from $quinn_utils (#34283):unroll by Quinn (#19845) Mon Mar 8 09:29:03 1993 PST"; 2":flatten(LIST list_of_lists) => LIST of all lists in given list `flattened'"; 3newlist = {}; 4for elm in (args[1]) 5if (typeof(elm) == LIST) 6newlist = {@newlist, @this:flatten(elm)}; 7else 8newlist = {@newlist, elm}; 9endif 10endfor 11return newlist;
longest shortest
Referenced by
- #30:columnize line 2:
$list_utils:longest - #59:callers_text line 27:
lu:shortest - #71:exit_alias_builder line 39:
$list_utils:shortest - #71:exit_alias_builder line 64:
$list_utils:shortest - #104:tell_exits line 21:
$list_utils:longest - #104:tell_exits line 26:
$list_utils:longest - #104:huh line 27:
$list_utils:shortest - #104:huh line 31:
$list_utils:shortest - #118:exit_name line 2:
$list_utils:shortest
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
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
Referenced by
- #4:@sort-owned*-objects line 10:
$list_utils:reverse_suspended
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
Referenced by
- #55:reverse_suspended line 4:
this:_reverse_suspended - #55:_reverse_suspended line 5:
this:_reverse_suspended - #55:_reverse_suspended line 5:
this:_reverse_suspended
Source
1":_reverse(@list) => reversed list"; 2set_task_perms(caller_perms()); 3(ticks_left() < 4000) && suspend(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
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)); 7(ticks_left() < 4000) && suspend(0); 8endfor 9return plist;
swap_elements
Referenced by
- #55:amerge line 12:
this:swap_elements
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
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
Referenced by
none
Source
1"assoc_suspended(target,list[,index]) returns the first element of `list' whose own index-th element is target. Index defaults to 1. Suspends as necessary."; 2"returns {} if no such element is found"; 3set_task_perms(caller_perms()); 4{target, thelist, ?indx = 1} = args; 5for t in (thelist) 6if (`t[indx] == target ! E_TYPE => 0') 7if ((typeof(t) == LIST) && (length(t) >= indx)) 8return t; 9endif 10endif 11(ticks_left() < 4000) && suspend(0); 12endfor 13return {};
amerge
Referenced by
none
Source
1"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."; 2{alist, ?tidx = 1, ?didx = 1} = args; 3if (alist) 4alist = this:sort_alist(alist, tidx); 5i = 1; 6res = {{cur = alist[1][tidx]}}; 7for tuple in (alist) 8if (tuple[tidx] == cur) 9res[i] = {@res[i], @listdelete(tuple, tidx)}; 10else 11if (didx != 1) 12res[i] = this:swap_elements(res[i], 1, min(didx, length(res[i]))); 13endif 14i = i + 1; 15res = {@res, {cur = tuple[tidx], @listdelete(tuple, tidx)}}; 16endif 17endfor 18return res; 19endif 20return alist;
build_alist
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;