[Grace-core] Class syntax

Daniel Gibbs gibbsdani at myvuw.ac.nz
Thu Jul 18 18:55:51 PDT 2013


> This the preferred way of doing it, except I would instead write:
> 
> class Cat.new(name')withColor(color') {
>    def name = name'
>    def color = color'
> }
> 
> class Cat.new(name') {
>    inherits Cat.new(name')withColor("blue")
> }
> 
> This convention (and it is only a convention) makes it clearer that you have a single class Cat, but with two constructors.

Sure. This currently does not work however; if I try to execute the following code in Minigrace:

class Cat.new(name')withColor(color') {
   def name is readable = name'
   def color is readable = color'
}

class Cat.new(name') {
   inherits Cat.new(name')withColor("blue")
}

var bob := Cat.new("Bob")

I get the error "No such method 'new()withColor()object' on Object." which isn't unsurprising given that when de-sugared, it results in binding two different factories to the same name "Cat", and in Minigrace, the second definition appears to override the first one, and indeed if I modify the last line to use the first constructor, I get the same error.

Daniel



More information about the Grace-core mailing list