list utilities #47
Aliases: list_utilities
71 verbs · 12 properties · 0 children
Verbs
| Verb | Spec | Flags | Definer | Lines |
|---|---|---|---|---|
make | this none this | rxd | #47 | 17 |
range range_suspended | this none this | rxd | #47 | 11 |
map_prop*erty | this none this | rxd | #47 | 10 |
map_verb | this none this | rxd | #47 | 10 |
map_arg*s | this none this | rxd | #47 | 17 |
map_builtin | this none this | rxd | #47 | 14 |
find_insert | this none this | rxd | #47 | 21 |
remove_duplicates | this none this | rxd | #47 | 6 |
arrayset | this none this | rxd | #47 | 8 |
setremove_all | this none this | rxd | #47 | 6 |
append | this none this | rxd | #47 | 9 |
reverse | this none this | rxd | #47 | 7 |
_reverse | this none this | rxd | #47 | 9 |
compress | this none this | rxd | #47 | 14 |
sort | this none this | rxd | #47 | 14 |
sort_suspended | this none this | rxd | #47 | 19 |
slice | this none this | rxd | #47 | 20 |
assoc | this none this | rxd | #47 | 9 |
iassoc | this none this | rxd | #47 | 12 |
iassoc_suspended | this none this | rxd | #47 | 14 |
assoc_prefix | this none this | rxd | #47 | 8 |
iassoc_prefix | this none this | rxd | #47 | 8 |
iassoc_sorted | this none this | rxd | #47 | 22 |
sort_alist | this none this | rxd | #47 | 57 |
sort_alist_suspended | this none this | rxd | #47 | 35 |
randomly_permute randomize | this none this | rxd | #47 | 7 |
count | this none this | rxd | #47 | 12 |
flatten flatten_suspended | this none this | rxd | #47 | 11 |
longest shortest | this none this | rxd | #47 | 19 |
check_nonstring_tell_lines | this none this | rxd | #47 | 10 |
reverse_suspended | this none this | rxd | #47 | 4 |
_reverse_suspended | this none this | rxd | #47 | 11 |
randomly_permute_suspended | this none this | rxd | #47 | 9 |
swap_elements | this none this | rxd | #47 | 17 |
random_item random_element | this none this | rxd | #47 | 14 |
assoc_suspended | this none this | rxd | #47 | 16 |
amerge | this none this | rxd | #47 | 21 |
passoc | this none this | rx | #47 | 11 |
setmove | this none this | rxd | #47 | 10 |
iassoc_new | this none this | rxd | #47 | 17 |
build_alist | this none this | rxd | #47 | 17 |
sort_value | this none this | rxd | #47 | 11 |
find_insert_value | this none this | rxd | #47 | 22 |
sort_prop | this none this | rxd | #47 | 9 |
find_insert_prop | this none this | rxd | #47 | 19 |
map_verb_value | this none this | rxd | #47 | 11 |
amerge_suspended | this none this | rxd | #47 | 23 |
setremove_all_list | this none this | rxd | #47 | 8 |
list_is_a is_a | this none this | rxd | #47 | 7 |
sort_cardinal | this none this | rxd | #47 | 20 |
find_insert_cardinal | this none this | rxd | #47 | 23 |
same_sets | this none this | rxd | #47 | 14 |
sort_cardinal_suspended | this none this | rxd | #47 | 21 |
random | this none this | rxd | #47 | 5 |
count_list | this none this | rxd | #47 | 14 |
count_list_suspended | this none this | rxd | #47 | 14 |
group_objects | this none this | rxd | #47 | 22 |
as_list | this none this | rxd | #47 | 7 |
sum | this none this | rxd | #47 | 6 |
foldl | this none this | rxd | #47 | 7 |
remove_if remove_if_not remove_if_suspended remove_if_not_suspended | this none this | rxd | #47 | 18 |
tolist | this none this | rxd | #47 | 1 |
make_alist | this none this | rxd | #47 | 14 |
break_at | this none this | rxd | #47 | 13 |
is_one_of | this none this | rxd | #47 | 8 |
sort_callback | this none this | rxd | #47 | 10 |
_find_insert_callback | this none this | rxd | #47 | 20 |
are | this none this | rxd | #47 | 11 |
valid gamevalid | this none this | rxd | #47 | 8 |
implode | this none this | rxd | #47 | 10 |
sort_prop_suspended | this none this | rxd | #47 | 10 |
Properties
| Property | Definer | Flags | Owner | Value |
|---|---|---|---|---|
nonstring_tell_lines | #47 | r | #29 | {} |
help_msg | #72 | rc | #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 | #1 | rc | #29 | {"list_utilities"} |
description | #1 | rc | #29 | {"This is the list utilities utility package. See `help $list_utils' for more details."} |
object_size | #1 | r | #29 | {46615, 1298433815} |
hidden_verbs | #1 | rc | #29 | <clear> |
phelp_msg | #1 | rc | #29 | <clear> |
weight | #1 | rc | #29 | <clear> |
owner_verbs | #1 | rc | #29 | <clear> |
plural_name | #1 | rc | #29 | <clear> |
client_image | #1 | rc | #29 | <clear> |
listening | #1 | rc | #29 | <clear> |
Ancestry
Ancestors (nearest first): #72 Generic Utilities Package → #1 root
Children: none
Call graph
Source
make
Referenced by
- #9:_repair line 47:
$list_utils:make - #20:columnize line 4:
$list_utils:make - #20:columnize_suspended line 4:
$list_utils:make - #24:sort_topics line 3:
$list_utils:make - #27:levenshtein line 5:
$lu:make - #27:levenshtein line 5:
$lu:make - #38:parse_misc_headers line 14:
$list_utils:make - #47:group_objects line 9:
$lu:make - #51:_fix_preps line 23:
$list_utils:make - #52:wizard_list line 9:
$list_utils:make - #254:group_by_type line 3:
$lu:make - #317:@allitems line 52:
$lu:make - #318:wh*o line 14:
$lu: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 range_suspended
Referenced by
- #20:silence line 5:
$lu:range - #20:scramble line 5:
$lu:range - #20:silence_words line 9:
$lu:range - #37:date_sort line 8:
$list_utils:range
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
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
- #3:look_sky line 22:
$lu:map_verb - #3:tell_nearby_lights line 16:
$lu:map_verb - #3:tell_nearby_lights line 19:
$lu:map_verb - #6:friend*s line 15:
$lu:map_verb - #20:title_list*c line 4:
$list_utils:map_verb - #47:map_verb line 4:
this:map_verb - #47:map_verb line 4:
this:map_verb - #47:map_verb_value line 5:
this:map_verb - #47:map_verb_value line 5:
this:map_verb - #54:look_self line 7:
$lu:map_verb - #54:tell_contents_backup line 8:
$lu:map_verb - #54:count line 12:
$lu:map_verb - #104:butch*er line 18:
$lu:map_verb - #104:cut line 11:
$lu:map_verb - #107:tell_wearing line 27:
$lu:map_verb - #107:count line 12:
$lu:map_verb - #119:look_self line 36:
$lu:map_verb - #134:look_self line 29:
$lu:map_verb - #142:_brainscan line 3:
$lu:map_verb - #142:_brainscan line 25:
$lu:map_verb - #143:_brainscan line 10:
$lu:map_verb - #148:search line 8:
$lu:map_verb - #317:quickbar line 15:
$lu:map_verb - #334:del*ete line 31:
$lu: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*s
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
Referenced by
- #47:map_builtin line 8:
this:map_builtin - #47:map_builtin line 8:
this: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 - #24:sort_topics line 8:
$list_utils:find_insert - #27:add line 7:
$list_utils:find_insert - #27:add line 11:
$list_utils:find_insert - #27:contains line 2:
$list_utils:find_insert - #27:extract line 4:
$list_utils:find_insert - #27:extract line 5:
$list_utils:find_insert - #27:expand line 21:
$list_utils:find_insert - #27:contract line 19:
$list_utils:find_insert - #27:_union line 55:
$list_utils:find_insert - #27:_union line 87:
$list_utils:find_insert - #33:mail_catch_up line 18:
$list_utils:find_insert - #47:sort line 8:
this:find_insert - #47:sort_suspended line 12:
this:find_insert - #300:weighted_random line 11:
$lu: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
- #1:set_aliases line 18:
$lu:remove_duplicates - #2:@addalias*# line 50:
$list_utils:remove_duplicates - #2:@addalias*# line 82:
$list_utils:remove_duplicates - #2:@rmalias*# line 36:
$list_utils:remove_duplicates - #2:@rmalias*# line 72:
$list_utils:remove_duplicates - #6:hints line 25:
$lu:remove_duplicates - #30:_every line 6:
$list_utils:remove_duplicates - #44:object_match_failed line 23:
$list_utils:remove_duplicates - #50:find_property line 7:
$list_utils:remove_duplicates - #50:find_verb line 7:
$list_utils:remove_duplicates - #54:count line 12:
$lu:remove_duplicates - #65:clean_status line 10:
$list_utils:remove_duplicates - #98:superjerk line 8:
$lu:remove_duplicates - #98:superjerkname line 11:
$lu:remove_duplicates - #107:count line 12:
$lu:remove_duplicates - #138:smell line 29:
$lu:remove_duplicates - #167:biz_listperms line 9:
$lu: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
- #47: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
- #27:union line 3:
$list_utils:setremove_all - #27:intersection line 3:
$list_utils:setremove_all - #35: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
- #24:sort_topics line 13:
$list_utils:append - #45:limited_children line 4:
$lu:append - #45:limited_children_suspended line 5:
$lu:append - #47:append line 3:
this:append - #47:append line 3:
this: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
- #6:journal*s line 46:
$lu:reverse - #6:teach line 16:
$lu:reverse - #6:teach line 17:
$lu:reverse - #17:check_player_request line 48:
$list_utils:reverse - #33:mail_catch_up line 26:
$list_utils:reverse - #45:property_definer line 6:
$lu:reverse - #50:@task*s line 235:
$lu:reverse - #53:news_display_seq_full line 7:
$lu:reverse - #75:do_breakdown line 23:
$list_utils:reverse - #75:do_breakdown line 45:
$list_utils:reverse - #96:calc_best line 9:
$lu:reverse - #107:show_score_full line 65:
$lu:reverse - #107:show_score_full line 69:
$lu:reverse - #111:tell_health line 13:
$lu:reverse - #118:command_history line 19:
$lu:reverse - #150:tell_log line 1:
$lu:reverse - #167:do_fire line 29:
$lu:reverse - #167:summary line 17:
$lu:reverse - #167:biz_employees line 8:
$lu:reverse - #167:biz_takeover line 8:
$lu:reverse - #167:biz_inactives line 5:
$lu:reverse - #167:_old_takeover line 16:
$lu:reverse - #253:_changelog_object line 13:
$lu:reverse - #253:_changelog_all line 6:
$lu:reverse - #253:_changelog_all line 27:
$lu:reverse - #253:_changelog_critical line 38:
$lu:reverse - #283:look_self line 15:
$lu:reverse - #293:update_counts line 23:
$lu:reverse - #293:reset_top_counts line 36:
$lu:reverse - #293:display_top_allfolders line 28:
$lu:reverse - #293:jdn_msg_seq line 12:
$lu:reverse - #317:@countweapons line 22:
$lu:reverse - #317:calc_topvalue line 26:
$list_utils:reverse - #317:calc_topvalue line 30:
$list_utils:reverse - #317:@positions line 15:
$lu:reverse - #317:do_scope line 14:
$lu:reverse - #317:calc_topitems line 17:
$lu:reverse - #317:calc_topitems line 26:
$lu:reverse - #326:print_report line 14:
$lu:reverse
Source
1"reverse(list) => reversed list"; 2old = args[1]; 3new = {}; 4for i in [1..length(old)] 5new = {old[i], @new}; 6endfor 7return new;
_reverse
Referenced by
- #47:_reverse line 3:
this:_reverse - #47:_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 - #6:@nude line 6:
$lu:sort - #6:list_pref_categories line 13:
$lu:sort - #6:hints line 5:
$lu:sort - #17:boot_idlers line 34:
$list_utils:sort - #27:from_list line 2:
$list_utils:sort - #37:date_sort line 8:
$list_utils:sort - #47:sort_alist line 5:
this:sort - #47:sort_alist_suspended line 8:
this:sort - #76:help_msg line 17:
$list_utils:sort - #114:store_sorted_rooms_by_z line 8:
$lu:sort - #120:tell_index line 16:
$list_utils:sort - #150:@h-areas line 17:
$lu:sort - #167:biz_chatcolor line 14:
$lu:sort - #202:store_sorted_rooms_by_z line 11:
$lu:sort - #216:_tell_standings line 11:
$lu:sort - #216:_tell_standings line 16:
$lu:sort - #223:press line 24:
$lu:sort - #281:median line 6:
$lu:sort - #317:@whohas line 155:
$lu:sort - #317:@monsters line 83:
$lu:sort - #317:@positions line 15:
$lu:sort - #317:@monsters-xp line 43:
$lu:sort - #317:@monsters-new line 54:
$lu: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) 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
Referenced by
- #2:@sort-owned*-objects line 8:
$list_utils:sort_suspended - #2:@sort-owned*-objects line 10:
$list_utils:sort_suspended - #17:show_missing_help line 12:
$list_utils:sort_suspended - #50:whodo line 4:
$list_utils:sort_suspended - #57:look_self line 7:
$list_utils:sort_suspended - #75:do_breakdown line 23:
$list_utils:sort_suspended - #75:do_breakdown line 45:
$list_utils:sort_suspended - #167:summary line 26:
$lu:sort_suspended - #167:biz_inactives line 20:
$lu:sort_suspended - #281:median_suspended line 6:
$lu:sort_suspended - #317:@allitems line 80:
$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$command_utils:suspend_if_needed(interval); 18endfor 19return sorted_lst || sorted_keys;
slice
Referenced by
- #2:@sort-owned*-objects line 10:
$list_utils:slice - #3:sort_exits line 8:
$lu:slice - #5:find_recipe line 6:
$lu:slice - #6:tell_contents line 35:
$lu:slice - #6:@pref line 12:
$lu:slice - #6:ansi_sub line 11:
$lu:slice - #6:@addr*oom line 14:
$lu:slice - #6:tell_contents_sub line 5:
$lu:slice - #6:hints line 25:
$lu:slice - #9:_repair line 115:
$list_utils:slice - #20:colorize line 29:
$lu:slice - #33:@subscribe*-quick line 17:
$list_utils:slice - #38:msg_seq_to_msg_num_string line 3:
$list_utils:slice - #38:msg_seq_to_msg_num_list line 3:
$list_utils:slice - #47:sort_alist line 5:
this:slice - #47:sort_alist_suspended line 8:
this:slice - #49:@blacklist line 77:
$list_utils:slice - #49:@blacklist line 84:
$list_utils:slice - #51:callers_text line 8:
lu:slice - #51:tvold line 6:
$list_utils:slice - #54:tell_contents_sub line 16:
$lu:slice - #62:set line 39:
$list_utils:slice - #62:parsechoice line 5:
$list_utils:slice - #75:do_breakdown line 23:
$list_utils:slice - #75:do_breakdown line 45:
$list_utils:slice - #85:matrix_add line 10:
$list_utils:slice - #85:matrix_add line 14:
$list_utils:slice - #89:tell line 2:
$lu:slice - #89:tell line 2:
$lu:slice - #89:tell line 3:
$lu:slice - #96:calc_best line 10:
$lu:slice - #106:is_nemesis line 2:
$lu:slice - #107:tell_contents line 14:
$lu:slice - #119:_close line 28:
$lu:slice - #119:may_pick line 12:
$lu:slice - #127:fits_on line 15:
$lu:slice - #146:may_pick line 10:
$lu:slice - #166:add_hint line 14:
$lu:slice - #167:do_fire line 29:
$lu:slice - #167:summary line 17:
$lu:slice - #167:biz_promote line 13:
$lu:slice - #167:biz_demote line 17:
$lu:slice - #167:biz_listperms line 4:
$lu:slice - #167:biz_takeover line 8:
$lu:slice - #167:biz_inactives line 5:
$lu:slice - #167:biz_voteout line 31:
$lu:slice - #167:_old_takeover line 16:
$lu:slice - #216:change_reputation line 8:
$lu:slice - #216:_tell_standings line 3:
$lu:slice - #289:slice line 9:
$lu:slice - #293:display_top_seq line 31:
$lu:slice - #293:comment_msg_seq line 8:
$lu:slice - #317:@countweapons line 23:
$lu:slice - #354:initialize_connection line 5:
$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
- #1:verb_sub line 3:
$list_utils:assoc - #3:e line 2:
$lu:assoc - #4:co*nnect line 82:
$list_utils:assoc - #4:blacklist_remove*_temp line 10:
$list_utils:assoc - #4:blacklisted_temp line 11:
$list_utils:assoc - #4:blacklisted_temp line 13:
$list_utils:assoc - #17:check_prog_restricted line 7:
$list_utils:assoc - #20:colorize line 12:
$lu:assoc - #33:current_message line 10:
$list_utils:assoc - #33:get_current_message line 12:
$list_utils:assoc - #35:from_ctime line 7:
$list_utils:assoc - #38:parse_message_seq line 28:
$list_utils:assoc - #43:commands_info line 2:
$list_utils:assoc - #49:mcd_2 line 47:
$list_utils:assoc - #49:@unnewt line 16:
$list_utils:assoc - #49:@blacklist line 81:
$list_utils:assoc - #49:@blacklist line 95:
$list_utils:assoc - #49:@blacklist line 137:
$list_utils:assoc - #50:eval_value_to_string line 3:
$list_utils:assoc - #51:task_owner line 2:
$list_utils:assoc - #51:owns_task line 3:
$list_utils:assoc - #55:invoke line 4:
$lu:assoc - #62:get line 8:
$list_utils:assoc - #62:set line 38:
$list_utils:assoc - #62:show line 24:
$list_utils:assoc - #66:incoming_connection line 9:
$list_utils:assoc - #80:close line 6:
$list_utils:assoc - #80:controls line 1:
$list_utils:assoc - #80:close_data line 5:
$list_utils:assoc - #103:report_error line 7:
$lu:assoc - #107:verb_sub line 8:
$list_utils:assoc - #247:visit_room line 19:
$lu:assoc - #293:_pms line 30:
$list_utils:assoc - #293:parse_message_seq line 36:
$list_utils:assoc - #293:pms_old line 36:
$list_utils:assoc - #355:parse_send_args line 14:
$list_utils:assoc - #355:parse_receive_args line 12:
$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 ((typeof(t) == LIST) && `t[indx] == target ! E_RANGE => 0') 6return t; 7endif 8endfor 9return {};
iassoc
Referenced by
- #6:tell_contents_sub line 23:
$lu:iassoc - #11:add line 9:
$list_utils:iassoc - #33:set_current_message line 14:
$list_utils:iassoc - #33:make_current_message line 16:
$list_utils:iassoc - #33:kill_current_message line 7:
$list_utils:iassoc - #33:@subscribe*-quick line 78:
$list_utils:iassoc - #33:make_current_message_new line 16:
$list_utils:iassoc - #38:raw_send line 33:
$list_utils:iassoc - #41:next line 1:
$lu:iassoc - #41:@queue-grep line 22:
$lu:iassoc - #43:set_stateprops line 8:
$list_utils:iassoc - #47:count_list line 7:
this:iassoc - #47:count_list_suspended line 6:
this:iassoc - #49:@temp-newt line 18:
$list_utils:iassoc - #50:@canedit line 81:
$lu:iassoc - #50:@adderror line 3:
$lu:iassoc - #50:@adderror line 14:
$lu:iassoc - #62:set line 59:
$list_utils:iassoc - #66:close line 9:
$list_utils:iassoc - #80:open line 11:
$list_utils:iassoc - #80:wait_for_response line 12:
$list_utils:iassoc - #80:get_messages line 5:
$list_utils:iassoc - #80:open_data line 5:
$list_utils:iassoc - #80:get_data line 5:
$list_utils:iassoc - #80:put_data line 5:
$list_utils:iassoc - #80:listen line 12:
$list_utils:iassoc - #80:data_connection line 3:
$list_utils:iassoc - #106:remove_nemesis line 2:
$lu:iassoc - #167:record_shop_log_entry line 6:
$lu:iassoc - #178:location_for line 8:
$lu:iassoc - #290:parse_attributes line 13:
$list_utils:iassoc - #293:update_counts line 13:
$lu:iassoc - #293:update_counts line 35:
$lu:iassoc - #345:look_self line 27:
$lu:iassoc - #355:parse_receive_args line 19:
$list_utils:iassoc
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
Referenced by
- #38:resolve_addr line 49:
$list_utils:iassoc_suspended - #150:@analyze-beat line 18:
$lu:iassoc_suspended - #150:@analyze-beat line 30:
$lu:iassoc_suspended - #317:_add_source line 2:
$lu:iassoc_suspended
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
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
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
- #33:mail_catch_up line 22:
$list_utils:iassoc_sorted - #38:renumber line 10:
$list_utils:iassoc_sorted - #38:length_num_le line 3:
$list_utils:iassoc_sorted - #38: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
- #3:sort_exits line 7:
$lu:sort_alist - #6:@mess*ages line 50:
$lu:sort_alist - #6:list_prefs line 12:
$lu:sort_alist - #6:teach line 16:
$lu:sort_alist - #6:teach line 17:
$lu:sort_alist - #20:silence line 11:
$lu:sort_alist - #20:scramble line 11:
$lu:sort_alist - #20:silence_words line 10:
$lu:sort_alist - #47:sort_alist line 9:
this:sort_alist - #47:sort_alist line 10:
this:sort_alist - #47:amerge line 5:
this:sort_alist - #50:find_property line 27:
$lu:sort_alist - #50:find_verb line 27:
$lu:sort_alist - #50:@task*s line 234:
$lu:sort_alist - #51:show_who_listing line 42:
$list_utils:sort_alist - #51:show_who_listing line 43:
$list_utils:sort_alist - #90:who_html line 39:
$list_utils:sort_alist - #90:who_html line 40:
$list_utils:sort_alist - #96:calc_best line 9:
$lu:sort_alist - #107:show_score_full line 64:
$lu:sort_alist - #107:show_score_full line 68:
$lu:sort_alist - #114:@list-costs line 2:
$lu:sort_alist - #119:check_holders line 11:
$lu:sort_alist - #167:do_fire line 29:
$lu:sort_alist - #167:summary line 17:
$lu:sort_alist - #167:biz_employees line 8:
$lu:sort_alist - #167:biz_promote line 12:
$lu:sort_alist - #167:biz_demote line 16:
$lu:sort_alist - #167:biz_listperms line 4:
$lu:sort_alist - #167:biz_takeover line 8:
$lu:sort_alist - #167:biz_inactives line 5:
$lu:sort_alist - #167:biz_voteout line 30:
$lu:sort_alist - #167:_old_takeover line 16:
$lu:sort_alist - #253:log_for line 17:
$lu:sort_alist - #293:update_counts line 22:
$lu:sort_alist - #293:update_counts line 44:
$lu:sort_alist - #293:reset_top_counts line 35:
$lu:sort_alist - #293:reset_top_counts line 44:
$lu:sort_alist - #293:display_top_allfolders line 26:
$lu:sort_alist - #293:add_bottom line 3:
$lu:sort_alist - #307:forge line 16:
$lu:sort_alist - #307:forge_name line 38:
$lu:sort_alist - #307:forge_name line 40:
$lu:sort_alist - #317:@countweapons line 21:
$lu:sort_alist - #317:calc_topvalue line 25:
$list_utils:sort_alist - #317:calc_topvalue line 29:
$list_utils:sort_alist - #317:@compare line 175:
$lu:sort_alist - #317:calc_topitems line 17:
$lu:sort_alist - #317:calc_topitems line 26:
$lu:sort_alist - #318:_who line 84:
$lu:sort_alist - #318:_who line 86:
$lu:sort_alist - #318:_who line 88:
$lu:sort_alist - #334:@list-costs line 5:
$lu: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
- #17:show_netwho_listing line 45:
$list_utils:sort_alist_suspended - #47:sort_alist_suspended line 13:
this:sort_alist_suspended - #47:sort_alist_suspended line 14:
this:sort_alist_suspended - #47:amerge_suspended line 6:
this:sort_alist_suspended - #49:@guests line 41:
$list_utils:sort_alist_suspended - #50:whodo line 22:
$lu:sort_alist_suspended - #150:@analyze-beat line 40:
$lu:sort_alist_suspended - #150:@analyze-beat line 41:
$lu:sort_alist_suspended - #253:_changelog_critical line 18:
$lu:sort_alist_suspended - #283:look_self line 14:
$lu:sort_alist_suspended - #317:@whohas line 114:
$lu:sort_alist_suspended - #317:@countarmor line 30:
$lu:sort_alist_suspended - #317:child_counts line 36:
$lu:sort_alist_suspended - #317:child_counts line 40:
$lu: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$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
Referenced by
- #52:wizard_list line 7:
$list_utils:randomly_permute - #54:get_from line 2:
$lu:randomly_permute - #54:put_into line 2:
$lu:randomly_permute - #104:get_from line 3:
$lu:randomly_permute - #107:get line 62:
$list_utils:randomly_permute - #114:on_reset line 29:
$lu:randomly_permute - #114:random_room line 6:
$lu:randomly_permute - #146:get_from line 2:
$lu:randomly_permute - #147:skill_check_failed line 15:
$lu:randomly_permute - #148:get_from line 4:
$lu:randomly_permute - #214:change_random_pressure line 3:
$lu:randomly_permute - #214:average_pressures line 3:
$lu:randomly_permute - #307:make_candidate line 5:
$lu: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
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
Referenced by
- #3:_descriptive_map line 25:
$lu:flatten - #5:_push line 7:
$lu:flatten - #47:flatten line 5:
this:flatten - #313:find_in_spawns line 6:
$lu:flatten
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
Referenced by
- #24:columnize line 2:
$list_utils:longest - #51:callers_text line 27:
lu: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
- #2:@sort-owned*-objects line 10:
$list_utils:reverse_suspended - #317:@allitems line 81:
$list_utils:reverse_suspended - #317:@countarmor line 31:
$lu:reverse_suspended - #317:child_counts line 37:
$lu:reverse_suspended - #317:child_counts line 41:
$lu: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
- #47:reverse_suspended line 4:
this:_reverse_suspended - #47:_reverse_suspended line 5:
this:_reverse_suspended - #47:_reverse_suspended line 5:
this:_reverse_suspended
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
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
Referenced by
- #47:amerge line 13:
this:swap_elements - #47:amerge_suspended line 14:
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"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
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
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
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
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
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
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
Referenced by
- #47:sort_value line 8:
this:find_insert_value
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
Referenced by
- #2:tell_tree line 57:
$lu:sort_prop - #2:tell_tree line 59:
$lu:sort_prop - #2:tell_mytree line 63:
$lu:sort_prop - #2:tell_mytree line 66:
$lu:sort_prop - #6:journal*s line 46:
$lu:sort_prop - #6:teach line 7:
$lu:sort_prop - #6:job*s line 19:
$lu:sort_prop - #33:@subscribe*-quick line 22:
$lu:sort_prop - #47:sort_cardinal line 13:
this:sort_prop - #47:sort_cardinal_suspended line 13:
this:sort_prop - #214:update_wind_room line 2:
$lu:sort_prop
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
Referenced by
- #47:sort_prop line 6:
this:find_insert_prop - #47:sort_prop_suspended line 6:
this:find_insert_prop
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
Referenced by
- #50:whodo line 4:
$list_utils:map_verb_value
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
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
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
Referenced by
- #50:whodo line 3:
$lu:list_is_a - #270:_start line 11:
$lu:list_is_a
Source
1is = {}; 2for x in (args[1]) 3if (is_a(x, args[2])) 4is = listappend(is, x); 5endif 6endfor 7return is;
sort_cardinal
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
Referenced by
- #47:sort_cardinal line 17:
this:find_insert_cardinal - #47:sort_cardinal_suspended line 17:
this:find_insert_cardinal
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
Referenced by
- #95:try_wield line 12:
$lu:same_sets
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
Referenced by
- #3:list_exits line 14:
$lu:sort_cardinal_suspended - #3:list_exits_long line 5:
$lu:sort_cardinal_suspended - #3:list_exits_old line 12:
$lu:sort_cardinal_suspended
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
Referenced by
- #142:heartbeat line 2:
$lu:random
Source
1l = args[1]; 2if (!l) 3raise(E_INVARG); 4endif 5return l[random(length(l))];
count_list
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
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
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
Referenced by
- #3:smell line 9:
$lu:as_list - #5:description line 4:
$lu:as_list - #257:smell line 10:
$lu:as_list
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
Referenced by
- #50:paramedic line 112:
$lu:sum - #50:paramedic line 120:
$lu:sum - #104:butch*er line 18:
$lu:sum
Source
1":sum(list) => INT sum of all elements"; 2total = 0; 3for x in (args[1]) 4total = total + x; 5endfor 6return total;
foldl
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
Referenced by
- #6:_walkto line 16:
$lu:remove_if_not - #107:get line 52:
$lu:remove_if_not - #184:_finish line 12:
$lu:remove_if_not - #184:_finish line 13:
$lu:remove_if_not - #270:_finish line 17:
$lu:remove_if_not - #270:_finish line 18:
$lu:remove_if_not
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
Referenced by
none
Source
1return args;
make_alist
Referenced by
- #20:silence_words line 9:
$lu:make_alist - #312:packages line 1:
$list_utils:make_alist - #355:parse_send_args line 24:
$list_utils:make_alist
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
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
Referenced by
- #55:pinch_ok line 14:
$lu:is_one_of - #138:rot_check line 31:
$lu:is_one_of
Source
1{what, cand} = args; 2is = {}; 3for c in (cand) 4if (is_a(what, c)) 5is = {@is, c}; 6endif 7endfor 8return is;
sort_callback
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
Referenced by
- #47:sort_callback line 7:
this:_find_insert_callback
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
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
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
Referenced by
- #6:wear line 3:
$lu:implode
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
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;