The Back-Tick Syntax

142 views
Skip to first unread message

Seyed H. HAERI (Hossein)

unread,
Mar 13, 2013, 9:07:05 AM3/13/13
to scala-user
Dear all,

When I change

val pi1 = g.`:`(e)

to the familiar dot-less method application version

val pi1 = g `:` e

I get the following error:

Multiple markers at this line
 - value : is not a member of type parameter Exp
 - value : is not a member of type parameter Exp

Is that not a bug? Looks like the lexifier is mistakenly processing "`:`" with the special treatment rules for ":". I say this g above is of type Heap[Exp] and e is of type Exp. (I'm using 2.10 at the moment.)

TIA,
--Hossein

--------------------------------------------------------------------------------------------------------------

Seyed H. HAERI (Hossein)

Research Assistant
Institute for Software Systems (STS)
Technical University of Hamburg (TUHH)
Hamburg, Germany

ACCU - Professionalism in programming - http://www.accu.org/
--------------------------------------------------------------------------------------------------------------

Seyed H. HAERI (Hossein)

unread,
Mar 13, 2013, 9:13:01 AM3/13/13
to scala-user
... Just for the sake of testing, I renamed the `:` method to `+` and realised that if I change

val _ = g.`+`(x)

to

val _ = g `+` x

for some reason, the compiler thinks that I'm after

val _ = g + x

That is, it simply neglects the back-ticks when I try to use them in the like-named method in a dot-less syntax. Is that intentional? Or, a bug?
--

Jiayu Liu

unread,
Mar 13, 2013, 12:06:59 PM3/13/13
to Seyed H. HAERI (Hossein), scala-user
To me, it seems that it's not a matter of the back tick, instead, it's
because that all operator that ends in colon (:) are considered right
associative.

On Wed, Mar 13, 2013 at 9:13 PM, Seyed H. HAERI (Hossein)
> --
> You received this message because you are subscribed to the Google Groups
> "scala-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scala-user+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Seyed H. HAERI (Hossein)

unread,
Mar 13, 2013, 12:25:08 PM3/13/13
to scala-user
> To me, it seems that it's not a matter of the back tick, instead, it's because that all operator that ends in colon (:) are considered right associative.

But, why should `:` be considered such an operator? `:` ends in a back
tick after all, as opposed to a colon.

And, why the example below shows that the back tick gets disregarded
when used in a dot-less notation:

> > val _ = g.`+`(x)
> >
> > to
> >
> > val _ = g `+` x
> >
> > for some reason, the compiler thinks that I'm after
> >
> > val _ = g + x

Now, I wonder whether that's a part of the Scala spec or a bug?

Jiayu Liu

unread,
Mar 13, 2013, 12:42:36 PM3/13/13
to Seyed H. HAERI (Hossein), scala-user
No, it's not a bug. According to Scala Language Specification, and I
am looking at the PDF verions of 2.9, the 1.1 Identifier section says
and I quote:

Finally,an identifier may also be formed by an arbitrary string
between back-quotes (host systems may impose some restrictions on
which strings are legal for identifiers). The identifier then is
composed of all characters excluding the backquotes themselves.

Short version: backquotes are not part of the identifier.

Jiayu Liu

unread,
Mar 13, 2013, 12:49:09 PM3/13/13
to Seyed H. HAERI (Hossein), scala-user
> And, why the example below shows that the back tick gets disregarded
> when used in a dot-less notation:
>
>> > val _ = g.`+`(x)
>> >
>> > to
>> >
>> > val _ = g `+` x
>> >
>> > for some reason, the compiler thinks that I'm after
>> >
>> > val _ = g + x

Just to be clear, `+` and + are the same to the compiler. Only when
you used a reserve word or put a space or something, in identifiers
like thread.`yield`() or `this is fun` + `this is not fun`, are they
different.

g.+(x) and g + x are the same, g.:(x) and g : x are not. It's a matter
of left or right associative.

Seyed H. HAERI (Hossein)

unread,
Mar 13, 2013, 12:52:40 PM3/13/13
to scala-user
I see. Thanks! :)

pil

unread,
Mar 13, 2013, 1:10:38 PM3/13/13
to scala...@googlegroups.com, Seyed H. HAERI (Hossein)
So you could rewrite your example as:

val pi1 = e `:` g

and it should work.

Seyed H. HAERI (Hossein)

unread,
Mar 13, 2013, 3:13:35 PM3/13/13
to scala-user
> So you could rewrite your example as:
>
> val pi1 = e `:` g
>
> and it should work.

Yeah. But, in my target domain, the semantically correct order is "g:
e" -- for which, I already have the "g <::> e" syntax. My entire
motivation for thinking of `:` was that I thought, in addition to
enabling me to work with a single colon, it's relief of the right
associativity of the colon-trailing operators.
Reply all
Reply to author
Forward
0 new messages