[scala] backquotes

View: New views
4 Messages — Rating Filter:   Alert me  

[scala] backquotes

by Vladimir Kirichenko-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all!

scala> implicit def x[A](a: A) = new {def xx = a}
x: [A](A)java.lang.Object{def xx: A}

scala> 12 xx
res1: Int = 12

scala> 12.xx
res2: Int = 12

scala> 12.`xx`
res3: Double = 12.0

scala> 12.xx + 12.xx
res5: Int = 24

scala> 12.`xx` + 12.xx
<console>:6: error: x[Double](12.0).xx of type Double does not take
parameters
       12.`xx` + 12.xx
          ^

scala> 12.3.`xx` + 12.xx
res7: Double = 24.3

Scala code runner version 2.7.6.r0-b20090922195039 -- Copyright
2002-2009, LAMP/EPFL

Can anyone explain above error? It's very frustrating in relation to
DSLs & measurement units like `m/sec`.


--
Best Regards,
Vladimir Kirichenko



signature.asc (265 bytes) Download Attachment

Re: [scala] backquotes

by Paul Phillips-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Oct 23, 2009 at 01:47:53AM +0300, Vladimir Kirichenko wrote:
> scala> 12.xx + 12.xx
> res5: Int = 24
>
> scala> 12.`xx` + 12.xx
> <console>:6: error: x[Double](12.0).xx of type Double does not take
> parameters
>        12.`xx` + 12.xx
>           ^

That looks like a bug.  I just fixed that section of the parser because
5.days and friends had stopped working so I know what to do, but I can't
do it this second so you should open a ticket so I don't forget.

--
Paul Phillips      | All men are frauds.  The only difference between
Analgesic          | them is that some admit it.  I myself deny it.
Empiricist         |     -- H. L. Mencken
pal, i pill push   |----------* http://www.improving.org/paulp/ *----------

Re: [scala] backquotes

by Paul Phillips-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Oct 23, 2009 at 01:47:53AM +0300, Vladimir Kirichenko wrote:
> scala> 12.`xx` + 12.xx
> <console>:6: error: x[Double](12.0).xx of type Double does not take
> parameters
>        12.`xx` + 12.xx
>           ^

BTW this works like this, at least in trunk:

  (12).`xx` + 12.xx

The problem is that the way you have it is being parsed like this,
almost surely because the parser hasn't been informed that a legal
identifier can start with backtick:

  (12.)   `xx`  (+12.xx)

rather than the more desirable

  (12.xx)  +  (12.xx)

--
Paul Phillips      | We act as though comfort and luxury were the chief
Everyman           | requirements of life, when all that we need to make us
Empiricist         | really happy is something to be enthusiastic about.
pal, i pill push   |     -- Charles Kingsley

Re: [scala] backquotes

by Vladimir Kirichenko-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> That looks like a bug.  I just fixed that section of the parser because
> 5.days and friends had stopped working so I know what to do, but I can't
> do it this second so you should open a ticket so I don't forget.

https://lampsvn.epfl.ch/trac/scala/ticket/2514

--
Best Regards,
Vladimir Kirichenko