Greetings,
I was hoping to confirm a couple of things about Oz pattern matching and
type conversion. both in the context of reading integer data from a text
file, as follows:
fun {LoadData FILE}
case {FILE getS($)} of false then
nil
elseof DATUM then
{Int.toFloat {String.toInt
{Filter DATUM fun {$ C} C \= 13 end}}}
|{LoadData FILE}
end
end
An earlier suggestion saw me substitute pattern-based appends for explicit
'Append' calls to yield an incredible performance improvement [thanks again,
Raph - it's not a mistake I intend repeating :) !]. However, the code still
looks quite 'busy', and I was hoping to improve it if at all possible.
Firstly, I'd really like to avoid the 'Filter' call. The reason I'm using it
is that extraneous carriage return [ASCII 13] characters appear in some
natively [Win32] created text files; this removes them [if present] and has
the advanatge of being reasonably platform independant [i.e. same code works
untouched under Linux where this problem does not exist]. Since the
extraneous character appears at the end of each line [thus the last element
in the character / code list], I was wondering whether it was possible to
remove this character via pattern matching without the need for any
additional processing ?
My intuition tells me 'no'; because:
* Pattern matching does not work like regexs
* The item to be removed is in the list tail, and it is not
possible to specify this via pattern matching
Am I correct in making these assumptions, or have I missed something ?
Secondly, the file data are integer strings e.g.
12
26
1254
...
but will be processed as floats in the program, hence the type conversions.
I initially made use of 'String.toFloat' to effect the conversions but found
that the required conversions were not being carried out [that is, no '.0'
was being appended to each integer value] ! Experimentation showed that it
was first necessary to convert each string to integer type, then convert
each integer to float type in order to obtain valid floating point values.
My question here is: is this two-step conversion necessary to obtain valid
floating point values from integer string data ?
Any help appreciated.
Cheers,
Anthony Borla
P.S.
Is there an online search facility available for the Mozart mailing list
archives, or is it necessary to download the gzip files and perform local
searches of archive contents ?
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users