[Grace-core] specification for methods in types

Kim Bruce kim at cs.pomona.edu
Sat Jun 18 16:17:24 PDT 2011


I'm confused about what syntax we should be using for declaring methods in types.

Section 11 of the language spec says to use:
(1)
type Cat { 
	color : Color
	name : String 
	miceEaten : Number 
	miceEaten:=(Number) : Unit
}

I would have expected something more like the following (where the "()" could be omitted for the first three methods)
(2)
type Cat {
        color: () -> Color
        name: () -> String
        miceEaten: () -> Number
	miceEaten:= :(Number) -> Unit           // the extra colon before the parameter type is a bit weird here!
}

or the syntax that our local interpreter actually accepts 
(3)
type Cat {
        color () -> Color
        name() -> String
        miceEaten() -> Number
	miceEaten:= (Number) -> Unit
}

which omits all of the colons.

I don't know that I have strong preferences, though the first seems least consistent with our syntax for the actual methods in an object or class, which would be written (according to the language spec) as:

         method doSomething(p: ParamType) -> ResultType {...}

Staring at all of the possibilities, the one that seems the most consistent is (3), the one my students implemented.

If we were to reconsider the way we write actual methods to a form more like:

         method doSomething(p: ParamType): ResultType {...}

then I think the description of types in the spec (1) is consistent and would be fine.  Right now, however, it seems weird.  

What do you think?

Kim

P.S.  At the moment, our parser requires the "()" to indicate no parameters, though that will eventually be allowed to be omitted.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailhost.cecs.pdx.edu/mailman/private/grace-core/attachments/20110618/f9a4c66a/attachment.html>


More information about the Grace-core mailing list