( load "int.met" ) ;--------------------- ( load "seq.met" ) ;--------------------- ;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). ;E ; ; ffinv(f) reverses f. ; ( def _ops ( plus _ops ( makeff ( ( quote ffinv ) ( quote ( ( ( FF A B ) ) ( FF B SET A ) ) ) ) ) ) ) ;--------------------- ( def ffinv lambda ( f ) ( ff1 ( list b ( set a ( from a ( dom f ) ( equal ( ap f a ) b ) ) ) ) ( from b ( ran f ) ) ) ) ;--------------------- ; ; ff2seq(f,b) converts f into a sequence according to the order ; specified by f. "Holes" are replaced by default value b, ; eg: ff2seq([ 1-> "a",3->"x"],"hole") = < "a","hole","x" >. ; ( def _ops ( plus _ops ( makeff ( ( quote ff2seq ) ( quote ( ( ( FF INT B ) ( B ) ) ( LIST B ) ) ) ) ) ) ) ;--------------------- ( def ff2seq lambda ( f b ) ( let ( ( l ( seqInseg ( intMAX ( dom f ) ) ) ) ) ( seq ( if ( member i ( dom f ) ) ( ap f i ) b ) ( from i l ) ) ) ) ;--------------------- ; ; ff2ffs(f,na,nb) converts mapping d into a tuple set (see ffs.cam), ; given attribute names for domain and codomain. ; ( def _ops ( plus _ops ( makeff ( ( quote ff2ffs ) ( quote ( ( ( FF A B ) ( C ) ( C ) ) ( SET FF C B ) ) ) ) ) ) ) ;--------------------- ( def ff2ffs lambda ( f na nb ) ( set ( makeff ( na a ) ( nb ( ap f a ) ) ) ( from a ( dom f ) ) ) ) ;--------------------- ; ; ff2STRff(fk) converts domain and range elements of fk into strings, ; if possible. ; ( def _ops ( plus _ops ( makeff ( ( quote ff2STRff ) ( quote ( ( ( FF A B ) ) ( FF STR STR ) ) ) ) ) ) ) ;--------------------- ( def ff2STRff lambda ( fk ) ( let ( ( f ( lambda ( x ) ( if ( is STR x ) x ( if ( is INT x ) ( itoa x ) ( if ( is SYM x ) ( symstr x ) "ff2STRfferror" ) ) ) ) ) ) ( ff1 ( list ( f k ) ( f ( ap fk k ) ) ) ( from k ( dom fk ) ) ) ) ) ;--------------------- ; ; 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. ; ( def _ops ( plus _ops ( makeff ( ( quote ffByIndex ) ( quote ( ( ( FF A B ) ( LIST A ) ) ( LIST B ) ) ) ) ) ) ) ;--------------------- ( def ffByIndex lambda ( f l ) ( seq ( ap f a ) ( from a l ( member a ( dom f ) ) ) ) ) ;--------------------- ; ; 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. ; ( def _ops ( plus _ops ( makeff ( ( quote ffByIndex1 ) ( quote ( ( ( FF A B ) ( LIST A ) ( B ) ) ( LIST B ) ) ) ) ) ) ) ;--------------------- ( def ffByIndex1 lambda ( f l d ) ( seq ( if ( member a ( dom f ) ) ( ap f a ) d ) ( from a l ) ) ) ;---------------------