This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Possible mistake in language specification

5 replies
Aivar
Joined: 2011-08-11,
User offline. Last seen 42 years 45 weeks ago.

Hi,

Scala Language Specification at 6.12.3 says that infix operators
starting with '=' have higher priority than those starting with '<',
yet tests with Scala 2.9 show otherwise (and also Java has it vice-
versa).

Jean-Philippe Pellet helped me to notice this contradiction:
http://stackoverflow.com/questions/7022207/why-scala-changed-relative-pr...

best greetings,
Aivar

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Possible mistake in language specification

On Thu, Aug 11, 2011 at 14:45, Aivar wrote:
> Hi,
>
> Scala Language Specification at 6.12.3 says that infix operators
> starting with '=' have higher priority than those starting with '<',
> yet tests with Scala 2.9 show otherwise (and also Java has it vice-
> versa).

Did you take the "= as in assignment" exception into account?

>
> Jean-Philippe Pellet helped me to notice this contradiction:
> http://stackoverflow.com/questions/7022207/why-scala-changed-relative-pr...
>
> best greetings,
> Aivar
>
>

Aivar
Joined: 2011-08-11,
User offline. Last seen 42 years 45 weeks ago.
Re: Possible mistake in language specification

In test I compared '===', '<<<' and '>>>'

Aivar

On Aug 11, 8:48 pm, Daniel Sobral wrote:
> On Thu, Aug 11, 2011 at 14:45, Aivar wrote:
> > Hi,
>
> > Scala Language Specification at 6.12.3 says that infix operators
> > starting with '=' have higher priority than those starting with '<',
> > yet tests with Scala 2.9 show otherwise (and also Java has it vice-
> > versa).
>
> Did you take the "= as in assignment" exception into account?
>
>
>
> > Jean-Philippe Pellet helped me to notice this contradiction:
> >http://stackoverflow.com/questions/7022207/why-scala-changed-relative...
>
> > best greetings,
> > Aivar
>
> --
> Daniel C. Sobral
>
> I travel to the future all the time.

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Possible mistake in language specification

Oh, I see your point. Yes, indeed, this seems to be a mistake in the
reference (also present in PinS, and probably other books as well).

On Thu, Aug 11, 2011 at 14:45, Aivar wrote:
> Hi,
>
> Scala Language Specification at 6.12.3 says that infix operators
> starting with '=' have higher priority than those starting with '<',
> yet tests with Scala 2.9 show otherwise (and also Java has it vice-
> versa).
>
> Jean-Philippe Pellet helped me to notice this contradiction:
> http://stackoverflow.com/questions/7022207/why-scala-changed-relative-pr...
>
> best greetings,
> Aivar
>
>

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: Possible mistake in language specification
Thanks for catching this! I'll update the SLS. -- Martin

On Thu, Aug 11, 2011 at 7:45 PM, Aivar <aivar [dot] annamaa [at] gmail [dot] com> wrote:
Hi,

Scala Language Specification at 6.12.3 says that infix operators
starting with '=' have higher priority than those starting with '<',
yet tests with Scala 2.9 show otherwise (and also Java has it vice-
versa).

Jean-Philippe Pellet helped me to notice this contradiction:
http://stackoverflow.com/questions/7022207/why-scala-changed-relative-precedence-of-relational-vs-equality-operators-compar

best greetings,
Aivar




--
Martin Odersky
Prof., EPFL and Chairman, Typesafe
PSED, 1015 Lausanne, Switzerland
Tel. EPFL: +41 21 693 6863
Tel. Typesafe: +41 21 691 4967

E. Labun
Joined: 2010-06-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Possible mistake in language specification

The same applies to '!'.

I.e. both, '=' and '!', should be over the '<' '>' in the list in the SLS.

Test:

class Foo(name: String) {
override def toString = name
def >(o: Foo) = new Foo("(" + this + " > " + o + ")")
def !(o: Foo) = new Foo("(" + this + " ! " + o + ")")
def =#(o: Foo) = new Foo("(" + this + " =# " + o + ")")
}
val foo = new Foo("x")
println(foo ! foo > foo) // (x ! (x > x)) ==> '>' binds more tightly than '!'

println(foo =# foo ! foo) // ((x =# x) ! x)
println(foo ! foo =# foo) // ((x ! x) =# x) ==> '!' and '=' have the same precedence

--
Eugen Labun

On 2011-08-11 21:49, martin odersky wrote:
> Thanks for catching this! I'll update the SLS. -- Martin
>
> On Thu, Aug 11, 2011 at 7:45 PM, Aivar > wrote:

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland