I will definitely be keeping an eye on Nim. That aside, does anyone else find the fact that Nim treats "-1" differently to "- 1" (quotes added for clarity) a bit disconcerting?
(- 1)
and this: (-1)
Are completely different things (the latter is actually an error). Also in LiveScript ls> (- 2)
[Function]
ls> (-2)
-2
Also in Smalltalk, this: -3. "=> -1"
- 3. "=> Error!!!"
That's off the top of my head, I'm sure there are many other languages with this characteristic. Why would that be a problem? It's just a single (or a couple) parse rules to remember (but you get other benefits from it).EDIT: Derp, that's not true. (- 2) == (-2)
It's a minor wart, and probably never going to be fixed.
EDIT: clarified
Why is the latter an error?
In Common Lisp you can work around this by using a special syntax: `|-1|`, which forces reading the thing inside as a symbol. You can then define functions and call them this way:
(defun |+1| (x) (1+ x))
(|+1| 1) ;; => 2
[1] `1-` too, of course.> `|-1|`
Is there a name for that | operator - if it is one?
If X is 1, "-X" computes "¯1", and "¯X" is ill-formed.
EDIT: Ah, the documentation mentions:
> This also means that `-1 is always parsed as prefix operator so code like `0..kArraySize div 2 -1` needs to be changed to `0..kArraySize div 2 - 1`.