gracelang / minigrace

Self-hosting compiler for the Grace programming language
39 stars 22 forks source link

`once class` not recognized #274

Closed apblack closed 5 years ago

apblack commented 5 years ago

The syntax

once class wombat { ... }

should be legal and have the same meaning as

once method {
    object { ... }
}

by analogy with ordinary methods.

This ought to be easy to implement, because classes are parsed into methodNodes, which already support once

kjx commented 5 years ago

so, we've built singleton into the language....

apblack commented 5 years ago

I think that this is featherweight flyweight. We get Singleton using an object constructor rather than a class.

Should we not have once class, and instead require once method { object ...? Seems non-orthogonal.

kjx commented 5 years ago

On 12/04/2019, at 16:55PM, Andrew Black notifications@github.com wrote:

I think that this is featherweight.

you're right: flyweight.

We get Singleton using an object constructor rather than a class.

yeah, I know. although if the class has no parameters it collapses.

Should we not have once class, and instead require once method { object ...? Seems non-;orthogonal.

if we have once, we should have the othernce

although I prefer class/object ... is once.

apblack commented 5 years ago

although I prefer class/object... is once.

We did talk about that. Annotations are not supposed to change the semantics — just make things legal or illegal. I'm not sure if we really observe that rule, though.

apblack commented 5 years ago

Fixed in commit be6602a