[Grace-core] Class syntax

Kim Bruce kim at cs.pomona.edu
Fri Jul 19 09:19:23 PDT 2013


Actually, while I'm disappointed, I guess I'm not that surprised that it doesn't work.  It would take special handling to aggregate the new constructor with the old.  I guess we should think carefully about the consequences.  It seems all good with class definitions, but a bit weird if we allowed this with regular objects.

Kim



On Jul 18, 2013, at 6:55 PM, Daniel Gibbs <gibbsdani at myvuw.ac.nz> wrote:

>> 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