We need more keywords
mail.openjdk.java.net
mail.openjdk.java.net
The only language I can think of that does this extensively is Haskell (and some flavors of regular expressions). The main downside I have noticed is that the ability to do this allows for the language to add a bunch of complexity that would otherwise be prevented by the need to preserve backwards compatibility [1]; but, if the language writers can remain disciplined, it seems like an effective way to grow a language without the growing pains the article is discussing.
For adding keywords, this approach doesn't even add that much maintenance cost, as all the additional complexity is confined to the lexer.
[1] Or, as has happened several times with Haskell, add features that too broken to even be considered adding but for the fact they are always behind a flag.
Rust is doing the same thing (although on the level of crates (packages) instead of individual files). When you want to use new keywords like async/await, you have to declare your crate as using the 2018 edition of Rust (as opposed to the original 2015 edition). Crates using different editions can be freely mixed, so when a new edition is released, everyone can migrate to the new edition at their own pace.
Neither of these adds new keywords (ReasonML switches some around, e.g. match is now switch) but maybe one of these approaches might work for language features or breaking syntax changes or revisions.
Will you need a new keyword to enable your option for new keywords?
Having said that, we can probably implement it using only existing keywords. Maybe: import java.lang.extensions.assert.
(I assume Java has some reserved part of the package namespace they can use for this purpose. Even if they don't, it shouldn't be difficult to find a package name that hasn't been used by anyone yet)
the lexer can always tell with fixed lookahead whether `a-b` is three tokens or one
How does that work? It doesn't seem obvious to me?I also wonder what approaches other languages have taken since I haven't seen dashed keywords in any of the other big languages.
Assume that "-" is the MINUS token. This means that, starting with the first character in "a", we have the token string "A MINUS B", which we can determine with a 3 token lookahead.
Now, if either A or B are reserved keywords, the lexer knows that "A MINUS B" is not correct (unless the grammar happens to allow for a keyword to occur next to a minus sign, which I don't think Java does. If it does, then you just avoid using that keyword when deriving a new one). At this point, the lexer and lex it as "A-B", which is (hopefully) a keyword.
I can't think of any examples, but I feel like I have seen languages reserve take a simmiliar approach where they reserve a prefix, which allows them to create as many new reserved words as they like.
- C has given up on new identifiers save the "reserved namespace", consisting of an underscore followed by an Uppercase, which is how you get _Bool and _Generic. Oof, nuff said.
- C++ has stretched poor `static` to its limits, and now incorporates context-sensitive "identifiers with special meaning": `final` and `override`. No new hard keywords in C++17 AFAIK.
- C# takes this even further with its LINQ-driven contextual keywords.
- JavaScript stumbles about by adding new identifiers, BUT only in strict mode, and even then only sometimes; `yield` is especially ambiguous.
Fill in the blanks please!
It's interesting to read about the musings and decision making processes for different languages, though. I'm sure Java and C# are both designed very carefully, yet with radically different goals and outcomes. And I'm sure both language design teams must ponder pretty much the same issues.