Hello,
Thanks both replies from Sachin and Till,
as mentioned I am new to functional coding,
Current I am not begin to study pattern matching
style yet, though it's really amazing me a lot!!
The begin...end statement did make recursive
call part of the else clause and figure out
my silly question.
--- In ocaml_beginners@yahoogroups.com, "Till
Crueger" <crueger ...>
wrote:
>
> >
> > I am new to functional programming
> > It always print "Fatal error: exception
Division_by_zero"
> > at the end of the program. Can anyone explain
why ?
>
> The Problem is that the recursive calll is not part of
the else
statement,
> as you might thing based on your indentation.
> As you can see now the recursive call is allways
executed. Instead you
> could write:
>
> let rec gcd a b =
> (* let r = a mod b in *)
> if (a mod b) = 0 then
> Printf.printf "The G.C.D is %d\n"
b
> else
> begin
> Printf.printf "processing r =
%d\n" (a mod b);
> gcd b (a mod b)
> end
> ;;
>
> let a = int_of_string Sys.argv.(1) in
> let b = int_of_string Sys.argv.(2) in
> if !Sys.interactive then
> ()
> else
> gcd a b;;
>
> now the call is actually part of the else clause.
>
> HTH,
> Till
> --
> Precisely why all the above should be so is not clear,
but goes some
way
> to explain why, on the disc, the Gods are not so much
worshipped as
blamed.
> --Terry Pratchett (The color of magic)
>
Archives up to August 22, 2005 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http:/
/groups.yahoo.com/group/ocaml_beginners/
<*> To unsubscribe from this group, send an email to:
ocaml_beginners-unsubscribe@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.c
om/info/terms/
|