[mercury-users] Accepting Values from the user
Fergus Henderson
fjh at cs.mu.OZ.AU
Wed Oct 16 00:51:54 AEST 2002
On 15-Oct-2002, Noel Pinto <cool4life at rediffmail.com> wrote:
> On Sat, 12 Oct 2002 Fergus Henderson wrote :
> >main -->
> > print("Enter an int: "), flush_output,
> > read_int(Int),
> > print("You entered: "), print(Int), nl.
>
> What is the purpose of puttinf 'flush_output'? The code works fine
> without it, So what's the need?
The output stream might be line buffered -- i.e. the actual
output might not occur until you either print a newline or
call flush_output.
> >:- pred read_int(int::out, io__state::di, io__state::uo) is
> >det.
> >read_int(Int) -->
> > io__read_line_as_string(Result),
> > {
> > Result = ok(Line),
>
> Does 'ok(Line)' mean it is checking whether the line is empty? Is
> 'Line' a variable?
Yes, Line is a variable. The unification `Result = ok(Line)'
tests whether `Result' was bound to ok(...) or to some other functor.
If Result was bound to ok(...), then Line is set to the value
that appears inside the ok(...) in Result.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list