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.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr 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 1C089BBAF for ; Mon, 6 Apr 2009 06:42:15 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEADMl2UmCNhAB/2dsb2JhbADHe4QPBg X-IronPort-AV: E=Sophos;i="4.39,328,1235948400"; d="scan'208";a="37925588" Received: from kurims.kurims.kyoto-u.ac.jp ([130.54.16.1]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 06 Apr 2009 06:42:13 +0200 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.8/8.13.8) with ESMTP id n364g8kv013190; Mon, 6 Apr 2009 13:42:08 +0900 (JST) Date: Mon, 06 Apr 2009 13:41:55 +0900 (JST) Message-Id: <20090406.134155.147748336.garrigue@math.nagoya-u.ac.jp> To: goswin-v-b@web.de Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Execution order in class construction From: Jacques Garrigue In-Reply-To: <87vdpligvy.fsf@frosties.localdomain> References: <87vdpligvy.fsf@frosties.localdomain> X-Mailer: Mew version 4.2 on Emacs 22.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; foo:01 val:01 val:01 printf:01 printf:01 unspecified:01 caml-list:01 behaviour:01 explicitly:02 explicitly:02 defined:02 garrigue:03 garrigue:03 seems:03 jacques:03 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. 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. Jacques Garrigue