On Wednesday, 5 October 2016 at 18:41:02 UTC, Jacob Carlborg wrote:
On 2016-10-05 19:14, Matthias Klumpp wrote:

Agreed - I have exactly the same problem with "version", which is also really common for, well, to hold a version number of a component. Body
is annoying too.

But, can keywords actually sanely be removed from the language without
breaking the world?

In Ruby most keywords are not reserved words. Example:

class Foo
  def class
  end
end

When the compiler sees the second "class" it already knows that this is a method declaration because of the "def" keyword. Actually calling this method requires a receiver:

class Foo
  def class
  end

  def bar
    class # this won't compile
self.class # this will work since the compiler knows that is has to be a method call because of the dot
  end
end

In Scala it's possible to wrap a keyword in backticks, this is necessary to be able to call a Java method that uses a name that is a keyword in Scala but not in Java:

// Java
class Foo
{
    void def () {}
}

// Scala
val a = new Foo()
a.`def`()

To remove D's current keywords and add them to the syntax would be quite an undertaking I think. If someone was so inclined, they could take the full syntax as it exists today, and try to modify it so that the keywords would be removed and added to the applicable grammar rules. I'd be curious to see how this would change the syntax rules, if it would be ALOT more complicated or if it only added some minor complication. My gut says that this would explode in complexity, but maybe not? You'd also have to make sure that the new syntax is still unambiguous, there's probably tools that can verify this.

Reply via email to