Proposal to add Extension Methods to the language

I think this syntax is the the way to go: write the definition in the same order as the usage.

Indeed, there is a generalization of this that allows interspersing of arguments and method names that perhaps we don’t actually want, but would allow less contorted creation of DSL syntax.

def (s: Seq) from (start: Int) until (end: Int) = ...

to replace xs.slice(3, 9) with xs from 3 until 9.

Anyway, I don’t necessarily advocate for this much generality (probably a pain to parse, and then there is ambiguity in a R b S c whether it’s a single method R(_)S(_) or the S method on the result of a R b.

However, if the extension method follows this form, I think it fits into the conceptual space of such things much more nicely than if we have magical new syntax.

5 Likes