Closed ozra closed 8 years ago
Actually, I kinda like redef
. We could go further, and make it easier to override a method:
type T ->
redef x(arg) ->
original(arg) + 1
Expands to:
class T
original_x = instance_method(:x)
def x(arg)
original_x.bind(self).(arg) + 1
end
end
original
is currently available through previous-def
, or super
if an inherited overridden. overridden
might be better for previous-def
. It is however one of those quirky-to-spell-for-non-en-mother-tongued "keywords".
I still feel redef should be more of an annotation than keyword. Func-names should have their primary spatial position. There are arguments for both positions of course. In any event, then it would look like this:
type Typ
x(arg) -> arg + 1
reopen Typ
x(arg) -> 'redef
overridden(arg) + 1
Hmm. I'd forgotten that we don't use def
... ;)
reop
, reopen
, etc. are left out in favour of ext
. Short, clean-sounding and correct english semantics (the full term). The full term extend
will also be allowed - it's a style choice. I will personally prefer using the abbreviation.
The construct extend Something
in Crystal will be include Something on Self
in Onyx (only one use-case in the entire compiler source, the lengthier syntax is more than OK imo)
type Typ
x(arg) -> arg + 1
ext Typ
x(arg) -> 'redef
overridden(arg) + 1
a-new-func() -> true
This is a hit. Further in #18.
This is something that costs very little effort, but can save a lot of unnecessary debugging time.
Now:
Proposed
The
reopen
is not considered the "to be" keyword. Suggestions are welcome. The important part is:type ...
is used for an existing type, there is an error.The natural continuation of this is of course member-funcs, which has been thought of for a while. I'm not to keen about requiring
'redef
pragma for all overrides though. I think this should be only for funcs defined asoverriding-is-bad
(there is nofinal
, just a suggestion, and'redef 'force
or something enables overriding anyway. Requiring `'redef' for all overrides (in order to ensure there actually is a method named as such that is overridden, and ensuring that a func is not named clashing with an existant unintentionally) should be an option through the idea of "code modes", and not standard.