;N txt.cam - a CAMILA library for text representation ;A J.N. Oliveira (jno@di.uminho.pt) ;D ; This library provides for a simple representation of (nested) text. ; Text can involve strings, integers and symbols. ;E ( deftype txt LIST txtEntry ) ;--------------------- ( deftype txtEntry ALT STR INT SYM txt ) ;--------------------- ; ; txtFlat(l) flattens l while converting integers and symbols to strings. ; ( def _ops ( plus _ops ( makeff ( ( quote txtFlat ) ( quote ( ( ( txt ) ) ( LIST STR ) ) ) ) ) ) ) ;--------------------- ( def txtFlat lambda ( l ) ( CONC ( seq ( if ( is STR x ) ( makeseq x ) ( if ( is INT x ) ( makeseq ( itoa x ) ) ( if ( is SYM x ) ( makeseq ( symstr x ) ) ( txtFlat x ) ) ) ) ( from x l ) ) ) ) ;--------------------- ; ; txt2File(fn,t) writes txt object t into file fn. ; This function will be replaced in future releases by ioTxt2File(fn,t) ; available in library io.cam. ; ( def _ops ( plus _ops ( makeff ( ( quote txt2File ) ( quote ( ( ( STR ) ( txt ) ) ( SYM ) ) ) ) ) ) ) ;--------------------- ( def txt2File lambda ( fn t ) ( let ( ( p ( txtFlat t ) ) ( _ ( princ "\nWarning: replace *txt2File* by *ioTxt2File* and include *io.cam*\n " ) ) ) ( progn ( sh ( strcat "rm " fn ) ) ( def _f ( fopen fn "w" ) ) ( foreach x p ( if ( equal x "" ) ( princ "." ) ( fputs x _f ) ) ) ( fclose _f ) ( sh ( strcat "ls -l " fn ) ) ) ) ) ;--------------------- ; ; txtAddNL(l) adds newline characters to every "line" in l. ; This may help in avoiding too long lines when dumping txt objects to ; files via txt2File. ; ( def _ops ( plus _ops ( makeff ( ( quote txtAddNL ) ( quote ( ( ( txt ) ) ( txt ) ) ) ) ) ) ) ;--------------------- ( def txtAddNL lambda ( l ) ( seq ( if ( or ( or ( is STR a ) ( is INT a ) ) ( is SYM a ) ) a ( append a ( makeseq "\n" ) ) ) ( from a l ) ) ) ;---------------------