weiqigao (1) [Avatar] Offline
#1
There seems to be a difference between "1.+(2)" and "1 .+(2)". Without a space between the "1" and the ".", Scala seems to lump the dot with the 1 and makes it a Double.

[weiqi@gao]$ scala
Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_07).
Type in expressions to have them evaluated.
Type :help for more information.

scala> 1.+(2)
res0: Double = 3.0

scala> 1 .+(2)
res1: Int = 3

scala>
santoshgokak (8) [Avatar] Offline
#2
Re: Scala: 1 + 2 equivalent to 1.+(2)?
This notation is deprecated in the upcoming 2.10 release and will be removed from 2.11.
Below is the output from the Scala 2.10 RC1 REPL.

C:UsersXYZDownloadsscala-2.10.0-RC1in>scala -deprecation
Welcome to Scala version 2.10.0-RC1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6
.0_33).
Type in expressions to have them evaluated.
Type :help for more information.

scala> 1. +(2)
<console>:1: warning: This lexical syntax is deprecated. From scala 2.11, a dot
will only be considered part of a number if it is immediately followed by a dig
it.
1. +(2)
^
<console>:2: warning: This lexical syntax is deprecated. From scala 2.11, a dot
will only be considered part of a number if it is immediately followed by a dig
it.
1. +(2)
^
<console>:8: warning: This lexical syntax is deprecated. From scala 2.11, a dot
will only be considered part of a number if it is immediately followed by a dig
it.
1. +(2)
^
res0: Double = 3.0

scala> 1.+(2)
<console>:1: warning: This lexical syntax is deprecated. From scala 2.11, a dot
will only be considered part of a number if it is immediately followed by a dig
it.
1.+(2)
^
<console>:2: warning: This lexical syntax is deprecated. From scala 2.11, a dot
will only be considered part of a number if it is immediately followed by a dig
it.
1.+(2)
^
<console>:8: warning: This lexical syntax is deprecated. From scala 2.11, a dot
will only be considered part of a number if it is immediately followed by a dig
it.
1.+(2)
^
res1: Double = 3.0

scala>
dcsobral (8) [Avatar] Offline
#3
Re: Scala: 1 + 2 equivalent to 1.+(2)?
All of these are Doubles: 1.0, 1. and .0

The second one, "1.", is being deprecated as of Scala 2.10. So, come Scala 2.11, "1.+(2)" will call the method + on the Int 1.

To be clear, "1.+(2)" right now is an *infix* call to the + method of Double's "1.".
martijn.verburg (86) [Avatar] Offline
#4
Re: Scala: 1 + 2 equivalent to 1.+(2)?
Thanks, we'll make a note of this in the Errata.