caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
Cc: goswin-v-b@web.de, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Execution order in class construction
Date: Mon, 06 Apr 2009 08:12:21 +0200	[thread overview]
Message-ID: <87r6069upm.fsf@frosties.localdomain> (raw)
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)")

Jacques Garrigue <garrigue@math.nagoya-u.ac.jp> writes:

> From: Goswin von Brederlow <goswin-v-b@web.de>
>
>> 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


      reply	other threads:[~2009-04-06  6:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-03 21:09 Goswin von Brederlow
2009-04-06  4:41 ` [Caml-list] " Jacques Garrigue
2009-04-06  6:12   ` Goswin von Brederlow [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r6069upm.fsf@frosties.localdomain \
    --to=goswin-v-b@web.de \
    --cc=caml-list@yquem.inria.fr \
    --cc=garrigue@math.nagoya-u.ac.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).