Extral Extra list manipulation commands

Home    Binary distributions    Source distribution    Documentation

list_remove listName ?item? ...
removes the items from the list
list_push listName ?item? ?position?
opposite of list_pop.
list_unshift listName ?item?
opposite of list_shift: prepends ?item? to the list.
list_set listName ?item? ?indexlist?
sets all elements of the list at the given indices to value ?item?
list_arrayset array varlist valuelist
sets the values of valuelist to the respective elements in varlist for the given array
list_common list list ...
returns the common elements of the lists
list_union list list ...
returns the union of the lists
list_eor list1 list2
returns the elements that are not shared between both lists
list_addnew listName ?item? ...
adds the items to the list if not already there
inlist list value
returns 1 if $value is an element of list $list returns 0 if $value is not an element of list $list
list_load filename
returns all lines in the specified files as a list
list_write file list
writes a list to a file
list_append list ?list1? ...
appends elements in list1 (and following) to list
eg.:
   % set list {1 2 3}
   1 2 3
   % list_append list {3 4} {5 6}
   % set list
   1 2 3 4 5 6
list_lappend list ?index...? ?list1? ...
appends one element to the sublist of list indicated by index
eg.:
   % set list {{a 1} {b 2}}
   1 2 3
   % list_lappend list 1 c
   % set list
   {a 1} {b 2 c}
   % list_lappend list 0 1 d
   % set list
   {a {1 d}} {b 2 c}
list_regsub ?switches? exp list subSpec
does a regsub for each element in the list, and returns the resulting list.
eg.:
	% list_regsub {c$} {afdsg asdc sfgh {dfgh shgfc} dfhg} {!}
	afdsg asd! sfgh {dfgh shgf!} dfhg
	% list_regsub {^([^.]+)\.([^.]+)$} {start.sh help.ps h.sh} {\2 \1}
	{sh start} {ps help} {sh h}
list_mangle ?list1? ?list2?
mangles two lists into one
eg.:
	% list_mangle {a b c} {1 2 3}
	{a 1} {b 2} {c 3}
list_extract ?list? ?expression?
tries to match each element in a list; if the element matches, it extracts the parenthesised part. It returns a list of all extracted parts. If there was no match, an empty element is put in the list.
eg.:
 
	% list_extract {Results {A: 50%} {B: 25%} {C: 25%}} { ([0-9+]+)\%}
		{} 50 25 25
list_split ?list? -before/-after/-outside ?positions?
splits a list at positions into sublists
eg.:
	% list_split {a b c d e} -before {1 3}
	a {b c} {d e}
list_join ?list? ?join string? ?position list?
joins list elements at positions given in the ?position list?. When you specify all, all elements will be joined.
eg.:
	% list_join {a b c {a d} e} { } {0 2}
		{a b} {c a d} e
	% list_join {a b c {a d} e} {} {0 2}
		ab {ca d} e
	% list_join {a b c {a d} e} {} all
	abca de
list_lengths ?list?
returns a list with the lengths of the elements
eg.:
	% list_lengths {abc abcdef}
	3 6
list_select ?mode? list pattern
selects all elements of a list that match a certain pattern. Default mode is -glob
eg.:
	% list_select {a b ab bc} a*
	a ab
	% list_select -regexp {a ab aa bc} {^[ab]*$}
	a ab aa
list_pop listName ?pos?
returns the last element from a list, thereby removing it from the list. If pos is given it will return the pos element of the list.
list_shift listName
returns the first element from a list, thereby removing it from the list.
list_sub list ?-exclude? [index list]
create a sublist from a set of indices When -exclude is specified, the elements of which the indexes are not in the list will be given.
eg.:
	% list_sub {Ape Ball Field {Antwerp city} Egg} {0 3}
	Ape {Antwerp city}
	% list_sub {Ape Ball Field {Antwerp city} Egg} -exclude {0 3}
	Ball Field Egg
list_find mode list pattern
returns a list of all indices which match a pattern. mode can be -exact, -glob, -regexp, -inlist, -oflist or -lcommon The default mode is -exact -inlist matches when the element at the index is a list that (exactly) contains the query as alist element -oflist matches when the element at the index (exactly) matches one of the elements in the query (which is regarded as alist) -lcommon both list elements and query are regarded as lists; they match if these lists have an element in common
eg.:
	% list_find -regexp {Ape Ball Field {Antwerp city} Egg} {^A}
	0 3
list_cor
gives the positions of the elements in list in the reference list. If an element is not found in the reference list, it returns -1. Elements are matched only once.
eg.:
	% list_cor {a b c d e f} {d b}
	3 1
	% list_cor {a b c d e f} {b d d}
	1 3 -1
list_remdup list
returns a list in which all duplactes are removed with the -sorted option the command will usually be a lot faster, but $list must be sorted with lsort; The optional $var gives the name of a variable in which the removed items will be stored.
list_lremove ?-sorted? list1 list2
returns a list with all items in list1 that are not in list2 with the -sorted option the command will usually be a lot faster, but both given lists must be sorted with lsort; The optional $var gives the name of a variable in which the removed items will be stored.
list_merge ?list1? ?list2? ??spacing??
merges two lists into one
eg.:
	% list_merge {a b c} {1 2 3}
	a 1 b 2 c 3
	% list_merge {a b c d} {1 2} 2
	a b 1 c d 2
list_unmerge ?list? ??spacing?? ??var??
unmerges items from a list to the result; the remaining items are stored in the given variable ?var?
eg.:
	% list_unmerge {a 1 b 2 c 3}
	a b c
	% list_unmerge {a b 1 c d 2} 2 var
	a b c d
	% set var
	1 2
list_reverse list
returns the reverse of the list.
list_change list change to ?change to ...?
change matching elements in a list to other values
list_concat list ?list? ?list ...?
This command treats each argument as a list and concatenates them into a single list If a single list is given, each element in this list is treated a a list, and concatenated
list_foreach varlist1 list1 ?varlist2 list2 ...? body
acts like foreach, except that list1, ... are treated as a list of lists and each iteration the next sublist is taken to fill the variables in varlist1, ...
eg.:
   % list_foreach {a b} {{1 2} {3 4}} {puts $a,$b}
   1,2
   3,4
   % list_foreach {a b} {{1 2 3} 4} {puts $a,$b}
   1,2
   4,
list_fill ?size? ?start? ??incr??
fills a list of ?size? elements with ?start?; if ?incr? is given and ?size? is a number, each element in the list will be the former incremented with ?incr? This works for integers or strings
eg.:
	% list_fill 4 "Hello world"
	{Hello world} {Hello world} {Hello world} {Hello world}
	% list_fill 5 2 2
	2 4 6 8 10
	% list_fill 5 10 -2
	10 8 6 4 2
list_subindex ?list? ?pos? ...
returns a list of the 'pos' element in each of the elements of the given list
eg.:
	% list_subindex {{a 1} {b 2} {c 3}} 1
	1 2 3

Peter De Rijk
hosted at Get extral at SourceForge.net. Fast, secure and Free Open Source software downloads