Message: 8 Date: Fri, 2 Dec 2005 10:33:03 +0100 From: Kevin Glynn <[EMAIL PROTECTED]> Subject: Oz Newbie: Pattern Matching and Type Conversion To: Anthony Borla <[EMAIL PROTECTED]> Cc: [EMAIL PROTECTED] Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=us-ascii
Kevin, > > Anthony Borla writes: > > Greetings, > > > > 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 ? > > > > You are correct, > Oz pattern matching code looks so much like Prolog code, and I figured it would be similar in this respect. I guess the 'Filter' call stays in for a while. > > but have you tried the Regex module? > Funny you should ask that. I'd *started* to look at this module, but ran into problems [not related to the current program] using things like 'Regex.replace' and 'Regex.forAll', and unable to solve them, shelved the attempt for a later time [besides, plenty of other Oz aspects to explore]. I don't suppose you've got a couple of simple examples of these routines laying around ;) ! There're definitely no examples in either the documentation or mailing list archive [I just searched using the link you gave below]. > > It would be more robust to use regex to extract the numbers > from each line. > Agreed. This will definitely be a later refinement. > > > > 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 ? > > > > Yes, I think so. String.tofloat insists that the string is in Oz > concrete syntax, which seems to mean that it should have > an explicit decimal point. > It makes sense since Oz seems to be fairly type strict but I just wanted to confirm that I wasn't doing any needless work. > > You could read them first into a list of integers then > map string.toFloat over them at the end, or write a helper > function that combines the two calls. > Thanks for the suggestion. Believe me when I say this 'little program' will be being heavily revised over the next few days / weeks since it's my 'Oz exploration / learning tool' :) ! > > > > 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 ? > > Yes, see the google search half way down this page: > > http://www.mozart-oz.org/lists/ > Many thanks for that. I'd been using this link [I think I Googled it]: http://www.ps.uni-sb.de/pipermail/mozart-users/ The archives are there, but definitely of limited value without a search facility. Cheers, Anthony Borla _________________________________________________________________________________ mozart-users mailing list [email protected] http://www.mozart-oz.org/mailman/listinfo/mozart-users
