3 ms·
This brings up an interesting problem for me. I've written a number of compilers where operators were not defined at parse-time, but handled via macros that ca
by daeken 17y ago
This brings up an interesting problem for me. I've written a number of compilers where operators were not defined at parse-time, but handled via macros that can be defined at any point. This makes the logic for transforming infix operators very difficult. If a change was made to make all operators operate left-to-right, this issue would go away. What do you guys think about this? Would it cause you serious problems while writing code?
- panic 17y agoThis is how Smalltalk does it. "Operators" are just binary messages that are evaluated from left to right.
- gruseom 17y agoIn addition to Smalltalk, the APL family (including J and K) do this too. It doesn't cause serious problems while writing code; once you get used to it, it's a whole lot simpler. It does, however, create a barrier to mainstream acceptance. So it seems to me your decision depends on how badly you want the latter.
- BigZaphod 17y agoI've often seen the claim that not having operator precedence hurts a language's acceptance, but is there any concrete evidence of that? Could it just be a coincidence? Were it not for the closed/licensed/expensive/commercial nature of Smalltalks, the language probably would not have fallen into to the relative obscurity it suffers today. I personally doubt that operators had anything to do with it. From what I've read of the history of the era, the language itself was much-loved and rising in popularity until the introduction of Java disrupted the traditional Smalltalk business models.
- silentbicycle 17y agoWhile it isn't exactly the same thing, OCaml requires you to use different operators (e.g. + vs. +.) for ints and floating point numbers, and it's a very common complaint about the language. (It has conventional precedence.) When conventional arithmetic doesn't "just work", languages will often give a first impression of being awkward, even though the rules of operator precedence are actually more complicated than just consistently using prefix or infix left-to-right.