The definiton for floating point literal in Scala is
floatingPointLiteral ::= digit {digit} ‘.’ digit {digit} [exponentPart] [floatType]
| ‘.’ digit {digit} [exponentPart] [floatType]
| digit {digit} exponentPart [floatType]
| digit {digit} [exponentPart] floatType
exponentPart ::= (‘E’ | ‘e’) [‘+’ | ‘-’] digit {digit}
floatType ::= ‘F’ | ‘f’ | ‘D’ | ‘d’
When I try to input floating point literal that starts with a dot I get an error:
scala> .123
^
error: ';' expected but double literal found.
If is assign such literal to some variable everything is fine
scala> val x = .123
x: Double = 0.123
Why it behaves like that?
Probably the quote you pasted is from the Syntax Summary.
Before we answer your question, let's notice the following:
So the issue here is not the floating point, but the fact that the expression starts with a dot. It makes the console, just like a regular Scala program, to evaluate the expression on the last object calculated.
Let's do an example:
As you can see, every new line, is a follow up of the previous. You can go back, for example:
But the object in cache is the last result.
In your example, probably the last successful run of your console was
val x = .123
, which put the lastres
as aDouble
. When you ran.123
you are starting anotherBlockStat
. The lexer identifies it is aBlock
, and therefore expects asemi
(which is a;
) between the differentBlockStat
s.When starting a new console, it works as expected: