MongooseA text-based world full of questionable inventions.

All help topics · Link to this topic

Showing help on '$seq_utils'

sequence utilities ($seq_utils #33)

A sequence is a set of integers (*)
This package supplies the following verbs:

:add (seq,f,t) => seq with [f..t] interval added
:remove (seq,f,t) => seq with [f..t] interval removed
:range (f,t) => sequence corresponding to [f..t]
{} => empty sequence
:contains (seq,n) => n in seq
:size (seq) => number of elements in seq
:first (seq) => first integer in seq or E_NONE
:firstn (seq,n) => first n integers in seq (as a sequence)
:last (seq) => last integer in seq or E_NONE
:lastn (seq,n) => last n integers in seq (as a sequence)

:complement (seq) => sequence consisting of integers not in seq
:union (seq,seq,...) => union of all sequences
:intersection (seq,seq,...) => intersection of all sequences
:contract (seq,cseq) (see `help $seq_utils:contract')
:expand (seq,eseq[,include]) (see `help $seq_utils:expand')

:extract(seq,array) => array[@seq]
:for([n,]seq,obj,verb,@args) => for s in (seq) obj:verb(s,@args); endfor

:tolist(seq) => list corresponding to seq
:tostr(seq) => contents of seq as a string
:from_list(list) => sequence corresponding to list
:from_sorted_list(list) => sequence corresponding to list (assumed sorted)
:from_string(string) => sequence corresponding to string

For boolean expressions, note that
the representation of the empty sequence is {} (boolean FALSE) and
all non-empty sequences are represented as nonempty lists (boolean TRUE).

The representation used works better than the usual list implementation for sets consisting of long uninterrupted ranges of integers.
For sparse sets of integers the representation is decidedly non-optimal (though it never takes more than double the space of the usual list representation).

(*) i.e., integers in the range [$minint+1..$maxint]. The implementation depends on $minint never being included in a sequence.


:add - add(seq,start[,end]) => seq with range added.
:contains(seq,elt) => true iff elt is in seq.
:complement(seq[,lower[,upper]]) => the sequence containing all integers *not* in seq.
:union(seq1,seq2,...) => union of all sequences...
:tostr - tostr(seq [,delimiter]) -- turns a sequence into a string, delimiting ranges with delimiter, defaulting to ..
:for([n,]seq,obj,verb,@args) => for s in (seq) obj:verb(s,@args); endfor
:extract - extract(seq,array) => list of elements of array with indices in seq.
:fromlist(list) => corresponding sequence.
:from_sorted_list(sorted_list) => corresponding sequence.
:size(seq) => number of elements in seq
:from_string(string) => corresponding sequence or E_INVARG
:firstn(seq,n) => first n elements of seq as a sequence.
:lastn(seq,n) => last n elements of seq as a sequence.
:range(start,end) => sequence corresponding to [start..end] range
:expand(seq,eseq[,include=0])
:contract(seq,cseq)
:_union(seq,seq,...)
:intersection(seq1,seq2,...) => intersection of all sequences...

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