

On Mon, 11 Nov 2002 Ralph Becket wrote :

>Even though other people may, don't use (_ -> ; _), use
>(if _ then _ else _) in your code.  It makes it much clearer 
>what's
>going on in your code.
>
>A switch would look like this
>
> 	(
> 		{ Res = ok(Str) },
> 		...
> 	;
> 		{ Res = eof },
> 		...
> 	;
> 		{ Res = error(Err) },
> 		...
> 	)
>
>Every possible binding of Res is tested for at the start of some 
>arm of
>the switch, which otherwise looks exactly like an ordinary 
>disjunction.
>
I have modified the code as to the one you suggested. It compiles 
well and the code is below...
:- module test3.

:- interface.
:- import_module io.
:- pred main(io__state::di, io__state::uo) is det.

:- implementation.

main -->
 	io__open_binary_input("blah.txt", Res),
 	(
 		{ Res = ok(Str)},
 		io__read_binary(Str, ResStr `with_type` io__result(string)),
 		(
 			{ResStr = ok(Binr `with_type` string)},
 			io__write_string(" Binary representation of a term is : "),
 			io__write_binary(Binr `with_type` string), nl
 		;
 			{ ResStr = eof },
 			io__write_string(" End of File.\n")
 		;
 			{ ResStr = error(Err1)},
 			io__write_string(" Error occured.\n"),
 			{ io__error_message(Err1, ErrMesg)},
 			io__write_string(ErrMesg)
 		)
 	;
 		{ Res = error(Err)},
 		{ io__error_message(Err, ErrMsg)},
 		io__write_string("Error occured: "),
 		io__write_string(ErrMsg)
 	).
While executing the code... I get a runtime error
$ ./test3
  Error occured.
Syntax error at variable `Dude': operator or `.' expected


blah.txt file contains the following text...
Hey Dude.

Bye Dude.

See ya Dude.

I have '.' as expected, so why is it that I get that error. How do 
I go about it??

Thanks and Regards,
Noel
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users@cs.mu.oz.au
administrative address: owner-mercury-users@cs.mu.oz.au
unsubscribe: Address: mercury-users-request@cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request@cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------

