On Wed, 13 Aug 2008 14:49:30 +0200, circ ular wrote:
> 
> what is the difference between "let rec" and just "let"? what does rec
> stand for?
> 
> are the following defintions exactly the same? at least they seem to
> give the same results...
> 
> # let rec cube x = x*x*x;;
> val cube : int -> int = <fun>
> # cube 12;;
> - : int = 1728
> 
> # let cubex x = x*x*x;;
> val cubex : int -> int = <fun>
> # cubex 12;;
> - : int = 1728
> #

The difference is that for [let x = e], [x] is not known in [e] (or
else, it is a previously defined [x]).  This allows the following
style (broadly used despite the thread on that topic):

  let r = .... in
  let r = .... r (* r of the previous line *) .... in
  let r = .... r (* r of the previous line *) .... in
  let r = .... r (* r of the previous line *) .... in
  ...

When using [let rec x = e], [x] is known in [e] which allows to define
recursive functions but also cyclic data :

  let rec x = 1 :: x

Hope it helps,
C.


P.S.  There exist a beginner list where these questions belong.

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to