Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jerome Vouillon <Jerome.Vouillon@inria.fr>
To: John Whitley <whitley@cse.buffalo.edu>, caml-list@inria.fr
Subject: Re: initialization of instance variables
Date: Thu, 1 Apr 1999 15:10:14 +0200	[thread overview]
Message-ID: <19990401151014.56489@pauillac.inria.fr> (raw)
In-Reply-To: <14077.2636.294799.938058@hadar.cse.Buffalo.EDU>; from John Whitley on Sat, Mar 27, 1999 at 01:04:33PM -0500

On Sat, Mar 27, 1999 at 01:04:33PM -0500, John Whitley wrote:
> 
> I'm curious as to why class instance variable definitions cannot be
> used in following instance variable definitions, only in methods and
> initializers.  Is this an implmentation-driven restriction, or is
> there some more subtle semantics-based reason to prevent this?

It would actually be quite easy to allow the use of an instance
variable in the following instance variable definitions.  The reason
it is not allowed for the moment is that I think it may be a bit
confusing.  Indeed, an identifier "x" in a method definition stands
for the current value of the instance variable "x" whereas, in an
instance variable definition, it would stand for the initial
definition of the instance variable.

For instance, if "o" is an object of the class "c" below, the
expression "o#get_y ()" will always evaluate to 1, whereas the
expression "o#get_x ()" will evaluate to 2 if the method "set" was
invoked previously.

    class c = object
      val mutable x = 1
      method set = x <- 2
      method get_x () = x
      val y = fun () -> x
      method get_y = y
    end

-- Jérôme




  reply	other threads:[~1999-04-01 18:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-27 18:04 John Whitley
1999-04-01 13:10 ` Jerome Vouillon [this message]
1999-04-01 15:01   ` John Whitley
1999-04-03 10:40     ` Hendrik Tews

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=19990401151014.56489@pauillac.inria.fr \
    --to=jerome.vouillon@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=whitley@cse.buffalo.edu \
    /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