SIP-???: Arbitrary idents and $" in interpolations#4663
SIP-???: Arbitrary idents and $" in interpolations#4663som-snytt wants to merge 2 commits intoscala:2.12.xfrom
Conversation
Allow arbitrary identifiers to be interpolated using
simple syntax, including backquoted identifiers.
Identifiers containing a dollar sign must be backquoted.
Accept `$"` for a literal quote.
```
scala> val foo = 42; val foo_ = 43; val foo_* = 44
foo: Int = 42
foo_: Int = 43
foo_*: Int = 44
scala> s"$foo_*"
res0: String = 44
scala> s"$`foo`_*"
res1: String = 42_*
scala> val `a..z` = (0 until 26) map ('a' + _) map (_.toChar)
a..z: scala.collection.immutable.IndexedSeq[Char] = Vector(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z)
scala> s"ABCs: $`a..z`"
res2: String = ABCs: Vector(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z)
scala> val foo$bar = 3
foo|: Int = 3
scala> s"<$`foo$bar`"
res3: String = <3
scala> s"$"Don't quote me on that!$" he objected."
res4: String = "Don't quote me on that!" he objected.
```
SIP-24 After photo, update the test check.
|
I would have thought that we'd need to first deprecate trailing underscores in interpolated ids to effect this change in a backwards compatible manner I realize this is a contrived example, but we need to spell out any potential compatibility breakages so we can weigh them against the benefits of this proposal. |
|
Yes, that's the big example of what parses differently. Maybe the community build can explain whether it's worth slowing down the rotation of the earth. I bet the biggest complainers would be people who had constants Another way of boosting the change: Hey, I spent three days in a Bold Radius fast track to Scala interpolation, and now I'm totally confused about what an identifier is. People want to spend their training dollars efficiently. Some intuitions derive from very ancient history, such as what is an alnum. Now that I've put in my time on Scala idents, I want it to pay dividends. |
|
Those BR guys are pretty good, I'm sure with a few hours of training (plus some homework) they could teach just about anyone:
The type checker and syntax highlighter will usually help out the people that weren't listening. |
|
:) Gah! Homework! Somewhere I noted that Martin slipped in the slip meeting and said ppl are pushing for underscore -- Martin is like my age so I sympathize -- so I think even one extra rule is one too many, etc. Life is too short. (I suspect Martin would agree, as that sentiment receives universal acclaim at a certain point.) I think you wanted extra help for What the typechecker should really be telling us is how many keystrokes are necessary to make this compile. And then the preso compiler can offer a quick fix. |
|
@SethTisue Doesn't that make it throw an exception every time it's referenced? |
|
Suspended: scala/slip#3 |
Allow arbitrary identifiers to be interpolated using
simple syntax, including backquoted identifiers.
Identifiers containing a dollar sign must be backquoted.
Accept
$"for a literal quote.Rebase of #3870