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=1.4 required=5.0 tests=SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 3E007BC70 for ; Sat, 11 Aug 2007 20:15:23 +0200 (CEST) Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.251]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l7BIFMUh011265 for ; Sat, 11 Aug 2007 20:15:22 +0200 Received: by an-out-0708.google.com with SMTP id b15so240660ana for ; Sat, 11 Aug 2007 11:15:22 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=mLzXRtXl+wO3PnIxKZ52ZDOwRwJGF6/Jx71SDONHz+kI3gJlzQVpQVZso1/PMjhBYjcXGkeTjnD/PJTLjazOboAnPcD+1W14PmUbXwz8qk5le8b1q7UOetFpWqOtK0Z+E59MJwY+VmBudrj59T47S/kOjEKloqL+0uof7nxPVWY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=snXVJUODfjQcAVLXvFDVbhqGyI6K21a66c0LMQ84KsXbZEKtM6p7oV7u2t0GVbea2iSmNWk8p7diTGIt0b9CsGk+mzCWzFamPzZy2f99yUhoSBfWgDUVHxhm9XIjBszayONyPyGvDie+EEJCI2Kmujs5BS59i7Wtx2YzYnC6Fd4= Received: by 10.100.142.12 with SMTP id p12mr3922094and.1186856121854; Sat, 11 Aug 2007 11:15:21 -0700 (PDT) Received: by 10.100.189.1 with HTTP; Sat, 11 Aug 2007 11:15:21 -0700 (PDT) Message-ID: <6806cf750708111115w3c3170abj3a4096ed95376222@mail.gmail.com> Date: Sat, 11 Aug 2007 14:15:21 -0400 From: "Jeff Meister" To: caml-list@yquem.inria.fr Subject: Re: Order of evaluation when constructing record values In-Reply-To: <6806cf750708111056v19107705p288e0b0bb152ef63@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <6806cf750708111056v19107705p288e0b0bb152ef63@mail.gmail.com> X-j-chkmail-Score: MSGID : 46BDFCBA.001 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 46BDFCBA.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; stdin:01 ocaml:01 forgiveness:98 wrote:01 ints:01 int:01 int:01 declaration:02 let:03 let:03 constructing:04 constructing:04 guess:04 pedantic:05 seem:08 I seem to have answered my own question by playing around. It appears that the order of evaluation is last-to-first and based on the order of the fields in the type declaration, not in the value construction. Oh well. I guess it's let-bindings for me. On 8/11/07, Jeff Meister wrote: > I ask for forgiveness in advance for this silly pedantic question. > > I think my question is best illustrated with an example. Say I have > this simple record type for holding a date: > > type date = { year : int; month : int; day : int; } > > Now, I want to read the year/month/day values from stdin, and I know > they will appear in that order. So I do the following: > > let today = { > year = read_int (); > month = read_int (); > day = read_int (); > } > > For this to work, I need the ints to be read in the order given, or I > could end up with a day of 2007 and a year of 11. Is there any > guarantee that OCaml will follow that order of evaluation when > constructing the record? Or do I have to force it with let-bindings > like this: > > let today = > let y = read_int () in > let m = read_int () in > let d = read_int () in > { year = y; month = m; day = d; } > > Of course, it's not that big a deal for me to just use the let-binding > method, but I'm curious, and it might make my code look nicer if I can > rely on order of evaluation. >