[Grace-core] initialisation & checking

James Noble kjx at ecs.vuw.ac.nz
Sat Apr 27 09:24:17 PDT 2013


[under the O'CAML rules]

> i.e., this is no longer a valid module:
>    method greet(name : String) {
>        print "Hello, {name}."
>    }
>    greet "visitor"
> 

because the last line is a self-call during construction.
Right. so *if* we went that way, modules are no longer objects -
or we'd have special rules for modules. and REPLs...
The original idea was that they'd be methods, not objects, but I 
like objects better! 

Note that a stronger "two phase" model, more directly following O'CAML
 - run all field initialisers top down, without self in scope, 
 - then run all mainline code top down, with self in scope
would allow that, with different semantics.  But it would be hard
to explain why 

  def foo = (print "a"; "a")
  print "b"
  def bar = (print "c"; "c") 

prints "a", "c" ,"b"  :-)

which is why O'CAML would write 

  def foo = (print "a"; "a")
  initializer {print "b"}
  def bar = (print "c"; "c") 

or Dart separates initializer lists & bodies like C++.
O'CAML & Dart maintain the split phase across inheritance.

I don't propose adopting these rules across the whole language
- although I'm fine with checked dialects enforcing them.

James


More information about the Grace-core mailing list