A variable-length color set. The values are a sequence whose color set must be the same type.
Declaration syntax
colset name = list name0 [with int-exp1..int-exp2];
Order
lexicographic (with respect to ordering of base color set)
Values
[v1, v2, …, vn]
where vi
has type name0
for i=1..n.
Optional with
clause
The with
clause specifies the minimum and maximum length of the lists.
Declaration examples
colset INTlist = list INT;
colset ShortBoolList = list Bool with 2..4;
var shortBoolList : ShortBoolList;
If Bool
has been declared as a Boolean color set, then the CPN variable shortBoolList
must be a list with length >=2 and <=4, and all values in the list must be either true
or false
. For example, [true,false]
and [false,true,false]
are legal values, but [true]
and [true,false,true,true,false]
are not.
Operations
See also color set functions.
List functions from Standard ML
nil
: empty list (same as[]
)e::l
: prepend element e as head of listl
hd l
‘: head, the first element of the listl
tl l
: tail, list with exception of first elementlength l
: length of listl
rev l
: reverse listl
map f l
: use functionf
on each element in listl
and returns a list with all the resultsapp f l
: use functionf
on each element in listl
and returns()
foldr f z l
: returnsf(e1, f(e2, ...,f(en, z) ...))
wherel = [e1, e2,..., en]
foldl f z l
: returnsf(en, ...,f(e2,f(e1, z)) ...)
wherel = [e1, e2,..., en]
List.nth(l,n)
:n
th element in listl
, where 0 <=n
<length l
List.take(l,n)
: returns firstn
elements of listl
List.drop(l,n)
: returns what is left after dropping firstn
elements of listl
List.exists p
: returnstrue
ifp
is true for some element in listl
List.null l
: returnstrue
if listl
is empty
For additional details and functions see the LIST structure in the SML Basis Library Manual.
Additional list functions
l1^^l2
: concatenate the two listsl1
andl2
mem l x
: returnstrue
if elementx
is in the listl
remdupl l
: removes duplicates from listl
rm x l
: removes the first appearance (if any) of elementx
from listl
rmall x l
: removes all appearances (if any) of elementx
from listl
contains l1 l2
: returnstrue
if all elements in listl2
are elements in listl1
, ignoring the multiplicity of elements inl2
contains_all l1 l2
: similar tocontains
but does not ignore multiplicity of elements inl2
intersect l1 l2
: returns the intersection of listsl1
andl2
union l1 l2
: returns the union, i.e. the concatenation, of listsl1
andl2
ins l x
: inserts elementx
at the end of listl
ins_new l x
: ifx
is not a member of listl
, thenx
is inserted at the end ofl
, otherwisel
is returnedsort lt_fun l
: sorts listl
using the functionlt_fun
to determine when one element in the list is less than another. Note that all color sets have a less-than functioncs.lt
(see color set functions).listsub l1 l2
: removes all elements in listl2
from listl1
. RaisesSubtract
if there is an element inl2
that is not inl1
.
See also Implementation of list functions for examples of how to use some of the the list functions, as well as to see how some of the functions are defined in Standard ML.
You must be logged in to post a comment.