SIP-24: Arbitrary idents and $" in interpolations#3870
SIP-24: Arbitrary idents and $" in interpolations#3870som-snytt wants to merge 1 commit 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.
```
|
It would be nice to include a preceding commit with a |
|
I was always wondering why |
|
@xeno-by Maybe I'll elaborate in the SIP document. |
|
@xeno-by Actually, the SIP already says: Imagine a localization macro that converts |
|
Isn't that just adding an additional way to do the same thing? What's the improvement of e. g. over ? |
|
@soc The point of that example is just that you get Conversely, though, is permitted in Scala even though it's just another way to write |
|
@som-snytt I agree that |
|
@xeno-by I misunderstood you.
If OTOH, $cala loves dollars. There must be a In a word, I sympathize but the gist of the discussions weighed against special-cased escapes. In one thread linked from SI-6476, Martin's phrase is "ugly special case." Even though he agrees that the behavior is not intuitive, or intended. I think a case might be made for guillemets. Then we could discuss how to pronounce guillemets. |
|
@retronym Not all are parse errs, because the |
|
I'm going to close this PR. We'll get back to the SIP review process after the summer, at which time the greek tick and calming "all is well" on this PR will be duly noted. |
|
I just needed this. For the record, also surprising how often I would use |
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.