From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA17382; Wed, 7 May 2003 17:43:23 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA17025 for ; Wed, 7 May 2003 17:43:21 +0200 (MET DST) Received: from epexch01.qlogic.org ([63.170.40.3]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h47FhKT06916 for ; Wed, 7 May 2003 17:43:20 +0200 (MET DST) Received: from epmailtmp.qlogic.org ([10.20.33.254]) by epexch01.qlogic.org with Microsoft SMTPSVC(5.0.2195.5329); Wed, 7 May 2003 10:42:11 -0500 Received: from [10.20.33.146] ([10.20.33.146]) by epmailtmp.qlogic.org with Microsoft SMTPSVC(5.0.2195.4905); Wed, 7 May 2003 10:42:11 -0500 Date: Wed, 7 May 2003 10:53:36 -0500 (CDT) From: Brian Hurt X-X-Sender: Reply-To: Brian Hurt To: David Brown cc: Hal Daume III , Neel Krishnaswami , "caml-list@inria.fr" Subject: Re: [Caml-list] why the "rec" in "let rec"? In-Reply-To: <20030507151603.GA21844@opus.davidb.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-OriginalArrivalTime: 07 May 2003 15:42:11.0075 (UTC) FILETIME=[395D3D30:01C314AF] X-Spam: no; 0.00; qlogic:01 caml-list:01 disallow:01 bug:01 idioms:01 wrappers:01 debugging:01 faq:01 beginner's:01 beginners:01 bin:01 caml-bugs:01 bindings:01 ocaml:01 caml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk An example of this in action- an efficient and portable way to find the high bit set in an int: let log2 x = if (x == 0) then -1 else let x, r = if (x < 0) then (x lsr 1), 1 else x, 0 in let x, r = if (Sys.word_size == 64) && (x > 0xFFFFFFFF) then (x lsr 32), (r + 32) else x, r in let x, r = if x > 0xFFFF then (x lsr 16), (r + 16) else x, r in let x, r = if x > 0xFF then (x lsr 8), (r + 8) else x, r in let x, r = if x > 0xF then (x lsr 4), (r + 4) else x, r in let x, r = if x > 0x3 then (x lsr 2), (r + 2) else x, r in let r = if x > 1 then (r + 1) else r in r Brian On Wed, 7 May 2003, David Brown wrote: > On Wed, May 07, 2003 at 07:57:13AM -0700, Hal Daume III wrote: > > > > let f x = .. > > > let f x = f x > > > > is to simply disallow bindings like this. I would think that they're > > almost always a bug. Especially if the first definition appears at the > > top of your file and the second (perhaps you forgot the "rec" and the body > > is actually long) appears at the bottom. Likely it would turn out to be a > > type error anyway, but why risk it? > > > > Anyway, I think the question was more along the lines of "why let the > > programmer do something like this." I cannot answer that. > > I hope it doesn't get disabled. There are some very common idioms that > use this type of declaration. > > let ... = > let a = ... a ... in > let a = ... a ... in > let a = ... a ... in > > This way, you can build up the value of a, almost like they were > assignments, but without the problems associated with mutable values. > It would be silly to have to keep thinking of new names for the variable > each time you did this. > > I have also made wrappers for functions for debugging purposes, and > found it very convenient to just be able to call the old definition. > > Dave Brown > > ------------------- > To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr > Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners