Here's a little bit of code paraphrased from a program I'm trying to write in Nim:
1 let foo:float64 = 200.
2 let bar = "x"
This does not compile:
dca@franz:/tmp$ nim compile testit.nim
Hint: used config file '/etc/nim.cfg' [Conf]
Hint: system [Processing]
Hint: testit [Processing]
testit.nim(2, 1) Error: invalid indentation
This works:
1 let foo:float64 = 200
2 let bar = "x"
as does this:
1 let foo:float64 = 200.0
2 let bar = "x"
I think this disagrees with the BNF given in the Nim Manual, specifically this:
FLOAT_LIT = digit (['_'] digit)* (('.' (['_'] digit)* [exponent]) |exponent)
The parenthesized construct after '.', namely, (['_'] digit)*, says that zero or more digits are required in this position (after the decimal point).
This would appear to be an error in the compiler or the BNF. If I've missed something, please explain. Thanks.
"It was a minor issue in the spec that has been fixed in the devel version of the manual."
But the devel version of the manual is not what users find when they consult the documentation on the Nim website.
As someone who spent 50 years of my life in software development, I completely understand that errors happen. But I do question your use of the word "minor". This was an error in the specification of the syntax of floating point literals, pretty basic in a programming language! And it was not "minor" to me, since I spent part of my day figuring out why my code wouldn't compile (with an error message that was not terribly helpful) and once I understood the problem, reporting a concise example version of it here, in case it was an unreported issue.
Also, I find it a bit hard to understand why the fix to the manual, which I see on github, was not applied to the production version of the manual (ala OpenBSD's errata applied to the Stable branch), instead of leaving a known error sitting there to bite more folks.
But I do question your use of the word "minor".
We have an issue tracker with 29 "high priority" bugs, the v0.19 release is overdue, so excuse me if my definition of "minor" differs from yours.
let foo:float64 = 200., it just doesn't look as something expected to work.
If you're coming from other languages, this is not unusual to see and to expect it works.
(It is not something I (would) do, but I have seen it in other people's (numerical) code)
You are correct.That form is valid C and C++ and makes perfect sense -- the trailing decimal point is sufficient to distinguish a floating point constant from an integer. This form is also acceptable in Rust and Go, so not just a characteristic of ancient languages.
Depending on the characteristics of the language, this form may make the language harder to parse, because of conflicts with other uses of '.'. This is why Haskell requires at least one digit after the decimal point and presumably why Nim has a similar requirement.
I don't think it's not in Nim because of parsing problems, it just doesn't look as a floating point value, especially at the end of a sentence - it then just looks as sentence terminator (and is even used so say in SmallTalk). And with all Nim's x and y vs. x&&y, if x: y else: z vs. x?y:z, var x: int vs. int x, yet addr, would saving here just one character be in line?
I didn't know it's widespread in C-like languages, but it's not an issue for them any way.
Yes, this syntax can then be expected by some newcomers, until the overall Nim's style is taken into account. Turns out, it's even allowed in JS and PHP. Yet I've never met it in any code. And a search through a bunch of JS libraries (even packed) did not give any example.