;; #include int.cam ;; #include seq.cam ;N ff.cam - a CAMILA library for finite mappings ;A J.N. Oliveira (jno@di.uminho.pt) ;D ; This library provides an enrichment of the finite mapping ; CAMILA built-in data algebra (functor A->B). ; Last Update: 1999.11.11 ;E FUNC ffinv(f:A->B):B->A-set ; ; ffinv(f) reverses f. ; RETURN [ b -> { a | a<- dom(f): f[a]==b } | b <- ran(f) ]; FUNC ff2seq(b:B,f:INT->B):B-seq ; ; ff2seq(b,f) converts f into a sequence according to the order ; specified by f. "Holes" are replaced by default value b, ; eg: ff2seq("hole",[ 1->"a" , 3->"x"]) = < "a","hole","x" >. ; RETURN let (l=seqInseg(intMAX(dom(f)))) in < if i in dom(f) then f[i] else b | i <- l >; FUNC ff2ffs(f:A->B,na:C,nb:C):(C->B)-set ; ; ff2ffs(f,na,nb) converts mapping d into a tuple set (see ffs.cam), ; given attribute names for domain and codomain. ; RETURN { [ na->a,nb->f[a]] | a <- dom(f) }; FUNC ff2STRff(fk:A->B):STR->STR ; ; ff2STRff(fk) converts domain and range elements of fk into strings, ; if possible. ; RETURN let (f=lambda(x).if is-STR(x) then x else if is-INT(x) then itoa(x) else if is-SYM(x) then symstr(x) else "ff2STRfferror") in [ f(k) -> f(fk[k]) | k <- dom(fk) ]; FUNC ffByIndex(f:A->B,l:A-seq):B-seq ; ; ffByIndex(f,l) lists the range of f using l as an index. ; Every entry in the index which f doesn't know about is lost. ; RETURN < f[a] | a <- l: a in dom(f) >; FUNC ffByIndex1(f:A->B,l:A-seq,d:B):B-seq ; ; ffByIndex1(f,l,d) is similar to ffByIndex(f,l) producing d as a ; default value for every entry in the index which f doesn't know about. ; RETURN < if a in dom(f) then f[a] else d | a <- l >;