Saturday, February 22, 2014

# in operator names to be removed

Originally I decided that in Loyc trees, '#' would be a prefix that meant "special" or "keyword". So reserved words or language constructs would be represented as identifiers that start with '#', e.g. #class, #enum, #for, #if, #while, etc.

Operators seemed special, so I also decided that operators would have the same prefix: #+, #==, #>>, etc. I've changed my mind, though, for two reasons:
  1. I no longer think operators are so special. LES and some other languages have an infinite number of potential operators and they're treated identically to normal functions, apart from their syntax.
  2. No language I know of uses the specific prefix '#'
  3. Most importantly, the syntax for naming operators turned out to be cumbersome: because an operator name like #+ generally cannot be used directly as an identifier in most languages, some sort of escaping mechanism is needed. In LES and EC# you have to write, in general, @`special identifier` (not just `special identifier` because the latter is treated as an operator, not an identifier). Therefore the identifier #+ is written @`#+` (@#+ also works in LES), which is a bit cumbersome and (more importantly IMO) creates a teaching challenge: I have to explain both what # is for and also what @ and the backticks are for, and the student must remember not to mix up @ and #. Plus, when someone encounters LES or EC# code for the first time it'll be harder to guess what @`#+` means compared to @`+`, and Google won't help ("Your search - @`#+` - did not match any documents.")
I've seen a few languages that allow you to use operators like identifiers. The conventions I've seen are: C#/C++ operator+, Haskell (+), and Nemerle @+. In all of these cases the additional characters near + can be understood as an escaping mechanism, so that the actual identifier name is simply +.

Therefore, I will soon dedicate a day or two to removing the hash characters from the beginning of all operators in both LES and EC#. Possibly, I'll remember to update the documentation too. We'll see.

No comments: