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 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id C829EBBAF for ; Mon, 6 Apr 2009 08:12:22 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnsFAFc62UnZSMDqZGdsb2JhbACBUpRHGgsDBwcPBbE4glGBPgaHOg X-IronPort-AV: E=Sophos;i="4.38,431,1233529200"; d="scan'208";a="27096287" Received: from fmmailgate03.web.de ([217.72.192.234]) by mail1-smtp-roc.national.inria.fr with ESMTP; 06 Apr 2009 08:12:22 +0200 Received: from smtp07.web.de (fmsmtp07.dlan.cinetic.de [172.20.5.215]) by fmmailgate03.web.de (Postfix) with ESMTP id 14376FA04859; Mon, 6 Apr 2009 08:12:22 +0200 (CEST) Received: from [78.43.226.218] (helo=frosties.localdomain) by smtp07.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #277) id 1Lqi4D-0001rU-00; Mon, 06 Apr 2009 08:12:21 +0200 Received: from mrvn by frosties.localdomain with local (Exim 4.69) (envelope-from ) id 1Lqi4D-00012B-DE; Mon, 06 Apr 2009 08:12:21 +0200 From: Goswin von Brederlow To: Jacques Garrigue Cc: goswin-v-b@web.de, caml-list@yquem.inria.fr Subject: Re: [Caml-list] Execution order in class construction References: <87vdpligvy.fsf@frosties.localdomain> <20090406.134155.147748336.garrigue@math.nagoya-u.ac.jp> Date: Mon, 06 Apr 2009 08:12:21 +0200 In-Reply-To: <20090406.134155.147748336.garrigue@math.nagoya-u.ac.jp> (Jacques Garrigue's message of "Mon, 06 Apr 2009 13:41:55 +0900 (JST)") Message-ID: <87r6069upm.fsf@frosties.localdomain> User-Agent: Gnus/5.110006 (No Gnus v0.6) XEmacs/21.4.21 (linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX1/p3h8odzutb0b2y5kIcAm2woHK7bQFieut6ElV iEBRTCW5fLNbFXFH8Pn/oychmh/4XoncyQE4/iZGyL9k9DVwc3 eIJeJBPDc= X-Spam: no; 0.00; foo:01 val:01 val:01 printf:01 printf:01 unspecified:01 foo:01 buffer:01 buffer:01 unspecified:01 compiler:01 mfg:98 caml-list:01 int:01 writes:01 Jacques Garrigue writes: > From: Goswin von Brederlow > >> I'm wondering if the execution order is defined during class >> construction. For example: >> >> let n = ref 0 >> let next () = incr n; !n >> class foo = object >> val x = next () >> val y = next () >> val z = next () >> method print = Printf.printf "%d %d %d\n" x y z >> end >> >> Will that always give x < y < z or could it initialize the values in >> different order? > > This is not explicitly specified in the manual (but not explicitly > left unspecified either). The same thing seems to be true for > initializers too. Things like that should really be specified. In that regard the docs are saddly lacking. With a specified in order execution the following could even be allowed: class foo buffer = object val num = int_from_buffer buffer val data = Array.init num (float_from_buffer buffer) end > The current implementation keeps the definition order, and I don't see > why it should change, but if your code depends on such things it may > always be a good idea to put somewhere a bit of code that verifies > that the behaviour is correct. How would you verify that? If the order is unspecified then it might just give x < y < z in one case and x > y > z for a slightly different case where the compiler optimized differently. I would have to verify every single class where the order is important. > Jacques Garrigue MfG Goswin