[clean-list] Re: Re: I AM LUNATIC (was: Easter Egg)
Siegfried Gonzi
siegfried.gonzi@kfunigraz.ac.at
Sat, 15 Sep 2001 18:52:26 +0200
Siegfried Gonzi siegfried.gonzi@kfunigraz.ac.at schrieb:
> Please forget what I wrote in the thread "Easter Egg". I am completely
> mad, I think for me there is no hope.
I am not sure anymore, whether there is really no hope.
The follwoing file (named "aer.txt" in the enclosed program):
12.34 123.34 7.23 2.43 23.34
3.45 2.34 3.7 2.34 23.45
2.76 4.76 2.34 6.5 2.34
7.56 23.34 23.4 2.43 23.34
delivers on the Mac and Clean 1.3.1 after reading it in an array:
({{12.34,123.34,7.23,2.43,23.34},{3.45,2.34,3.7,2.34,23.45},{2.76,4.76,2.34,6.5,2.34},{2.76,4.76,2.34,6.5,2.34},{7.56,23.34,23.4,2.43,23.34}},65536)
delivers on Windows NT 4 and Clean 1.3.3:
({{NAN,123.34,7.23,2.43,23.34},{3.45,2.34,3.7,2.34,23.45},{2.76,4.76,2.34,6.5,2.34},{2.76,4.76,2.34,6.5,2.34},{7.56,23.34,23.4,2.43,23.34}},65536)
and on the SunOS 8 and Clean 1.3.3:
({{9.45874455237136e-13,5.34741321642642e-313,2.25532375037858e-264,1.4122856227
4174e-43,3.67108485691916e-62},{4.66726071692992e-62,5.13438477071769e-313,2.503
43536253301e-264,4.87047766343204e-62,3.86132723820915e-86},{-8.67922223160672e+
209,9.45874455237136e-13,9.22215126761938e-309,3.67108478466139e-62,2.2553237503
7858e-264}},65536)
Enclosed the program. You can copy and paste it and on Unix you may have
to change probably the path-file name:
==
module arrayreadu
import StdEnv, StdFile
ReadArray:: {*{#Real}} !File -> {*{#Real}}
ReadArray marray file = ReadZeilen 0 marray file
where
ReadZeilen:: !Int {*{#Real}} !File -> {*{#Real}}
ReadZeilen i marray file
| i == (size marray) = marray
= ReadZeilen (i+1) (ReadSpalten 0 marray file) fileNextLine
where
(line,fileNextLine) = sfreadline file
ReadSpalten:: !Int {*{#Real}} !File -> {*{#Real}}
ReadSpalten j marray file
| j == (size marray.[0]) = marray
#! (b,double,file) = sfreadr file
= ReadSpalten (j+1) { marray & [i,j] = double } file
CountLines:: !File -> !Int
CountLines file = ReadLines 0 file
where
ReadLines:: !Int !File -> !Int
ReadLines nLines file
| sfend file = nLines
#! (line,filerest) = sfreadline file
= ReadLines (nLines + 1) filerest
ReadNLines:: !Int !File -> !File
ReadNLines n file
| n == 0 = file
#! (line, file) = sfreadline file
= ReadNLines (n - 1) file
LinesArray:: !Int !Int !Int -> !Int
LinesArray ni NHeader nLines
| (ni - NHeader) <= 0 = abort("Negative array index")
= (ni - NHeader)
MakeArray:: !Int !Int -> {*{#Real}}
MakeArray ni nj
| ni <=0 || nj <=0 = abort("Negative array index")
= {{0.0\\x <- [0..(nj-1)]}\\y <- [0..(ni-1)]}
Extract:: !String !*Files -> ({*{#Real}},!*Files)
Extract inputfile file
#! (readok, infile,file) = sfopen inputfile FReadText file
| not readok = abort ("Cannot read")
#! nLines = (CountLines infile)
#! Ni = LinesArray (nLines-1) NHeader nLines
#! marray = MakeArray Ni Nj
#! infile = ReadNLines (NHeader) infile
= ((ReadArray marray infile),file)
// File name
inputfile :== "/home/sig/clean/aero.txt"
// Number of header lines
NHeader:==0
// Number of columns
Nj:==5
Start:: *World -> ({*{#Real}},*World)
Start world = accFiles (Extract inputfile ) world
==
Is this a bug or an undocumendet strangeness? I am not a C expert and
therefore I have been not very interested in file streams and any
internals; but I didn't encounter any problems when I wrote file
handling programs in C on my Mac and run it on Windows; hence I am that
naive an expect this from Clean too.
Please notice: I didn't make an official bug report but I post it here.
I am not really sure whether it is a bug or I am not capable of handling
it appropiately.
S. Gonzi