From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 3DA1FBB84 for ; Wed, 13 Aug 2008 17:17:51 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgABAJCXokjBvsFKnWdsb2JhbACRdgEBAQEBCA0HpHSBVQ X-IronPort-AV: E=Sophos;i="4.32,201,1217800800"; d="scan'208";a="28197975" Received: from dnsp.umh.ac.be (HELO hermes1.umh.ac.be) ([193.190.193.74]) by mail4-smtp-sop.national.inria.fr with ESMTP; 13 Aug 2008 17:17:51 +0200 Received: from poincare.swapping.umh.ac.be ([10.102.100.10]) by hermes1.umh.ac.be (8.14.2/8.13.6) with ESMTP id m7DFEUCk602178; Wed, 13 Aug 2008 17:14:30 +0200 Received: from localhost ([127.0.0.1] ident=trch) by poincare.swapping.umh.ac.be with esmtp (Exim 4.69) (envelope-from ) id 1KTI6e-0001fI-If; Wed, 13 Aug 2008 17:17:48 +0200 Date: Wed, 13 Aug 2008 17:17:48 +0200 (CEST) Message-Id: <20080813.171748.1124003908241412727.Christophe.Troestler+ocaml@umh.ac.be> To: circularfunc@gmail.com Cc: OCaml Mailing List Subject: Re: [Caml-list] Difference between "let rec" and just "let"? From: Christophe TROESTLER In-Reply-To: References: X-Face: #2fb%mPx>rRL@4ff~TVgZ"<[:,oL"`TUEGK/[8/qb58~C>jR(x4A+v/n)7BgpEtIph_neoLKJBq0JBY9:}8v|j Organization: University of Mons-Hainaut X-Mailer: Mew version 6.0.51 on Emacs 22.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.64 on 193.190.193.76 X-Spam: no; 0.00; christophe:01 troestler:01 christophe:01 troestler:01 ocaml:01 0200,:01 val:01 val:01 recursive:01 wrote:01 rec:01 rec:01 caml-list:01 functions:01 cyclic:01 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 = > # cube 12;; > - : int = 1728 > > # let cubex x = x*x*x;; > val cubex : int -> int = > # 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.