I/O example needed

Ana Maria Abrao ana@ufu.br
Mon, 18 Jan 1999 11:16:02 -0200


> a) reads a file I into a big L list of chars (including newlines)
>    (the file is not too big so I do want to put it into a list)
> b) calls a function F to munge L around a bit
> c) writes the munged L out to another file O.
> 


module ListChar
import StdEnv

Munge xs= {toUpper x \\ x <- xs}

Start world
#	(ok, file, world)= fopen "test.txt" FReadText world
	(contents, file)= freads file  10000
	list= [x \\ x <-: contents]
	mString= Munge list
	(ok, file, world)= fopen "tested.txt" FWriteText world
	file= fwrites  mString  file
	(ok, world)= fclose file world
= world




A few comments. There is no reason to convert the string 'contents'
to a list of char. Clean is very efficient when working with
strings, matrices and arrays. Besides this, the language also
has very handy functions to process strings. However, since you
wants a list of chars, it is easy to transform strings to list
of chars. This is done in the line:

	list= [x \\ x <-: contents]

Make sure that your Start function returns the modified world
(i.e. the world with the processed file "tested.txt"). 
If you have any further questions, be free to contact us.
Take a look at our page:

	http://www.deene.ufu.br/clean/clean1.html

There, we discuss the Clean`s  input/output system.