[Grace-core] Class syntax

Andrew P Black black at cs.pdx.edu
Mon Jul 22 11:48:26 PDT 2013


On 22 Jul 2013, at 4:36, James Noble wrote:

> for the repl. 
> You need to allow 
> 
> def x = 3
> ...
> def x = 7 
> 
> in the same session 

No, we don't.  You are still thinking of "repl" in terms of a teletype.  Nowadays, we have editing buffers.   If you want to redefine x to be 7, all you need to is edit the 3 to be a 7, and press the "evaluate" button.  That evaluates the entire contents of the buffer again.

I would not expect an object with two definitions of aCat or two definitions of x to compile.  

However, classes are not definitions; they are special, since they combine a definition with an object expression.   We could allow multiple class constructs with the same object name and different factory method names to be additive.  Then we would be able to write:

> class aCat.named(n)withColor(c) {
>   def name = n
>   def color = c
>   method speak { 
> 		print "I'm a {color} cat; my name is {name}"
>   }
> }
> 
> class aCat.named(n) {
>   aCat.named(n)withColor("blue")
> }

This would create a factory object aCat with two methods,  named()withColor() and named().  Notice that there is no reason to use inheritance in the method 'named';  both of the factory methods create objects with the same method suite, and there is no inheritance relationship between them.

I'm not sure myself if this is worth the cost, but it would seem to be the simplest way of allowing students to move from  factories with a single method to factories with multiple methods.

	Andrew

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailhost.cecs.pdx.edu/pipermail/grace-core/attachments/20130722/ffa17f15/attachment.html>


More information about the Grace-core mailing list