Re: initialization of instance variables

From: Jerome Vouillon (Jerome.Vouillon@inria.fr)
Date: Thu Apr 01 1999 - 15:10:14 MET DST


Date: Thu, 1 Apr 1999 15:10:14 +0200
From: Jerome Vouillon <Jerome.Vouillon@inria.fr>
To: John Whitley <whitley@cse.buffalo.edu>, caml-list@inria.fr
Subject: Re: initialization of instance variables
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



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:21 MET