(I will open a ticket after I find out whether this is a spec bug or an implementation bug.)
This proceeds swimmingly:
scala> "the quick brown fox jumps over the lazy dog"
res0: String = the quick brown fox jumps over the lazy dog
scala> val fox = "bear" ; val dog = "value"
fox: String = bear
dog: String = value
scala> s"the quick brown $fox jumps over the lazy $dog"
res1: String = the quick brown bear jumps over the lazy value
If the original string has a quote in it, it's a bit of a different
story. It doesn't appear possible to embed quotes anymore. Here's
the most concise I found inside single quotes:
scala> "the quick brown fox jumps over the \"lazy\" dog"
res2: String = the quick brown fox jumps over the "lazy" dog
// Beautiful!
scala> s"the quick brown $fox jumps over the ${'"'}lazy${'"'} $dog"
res3: String = the quick brown bear jumps over the "lazy" value
The string interpolation spec says:
Inside a processed literal none of the usual escape characters are
interpreted (except for unicode escapes) no matter whether the string
literal is normal (enclosed in single quotes) or multi-line (enclosed in
triple quotes).
But if "the usual escape characters" are the ones in SLS 1.3.6, "EscapeSequences",
then in fact all of the usual escape characters are interpreted, except for
the double quote. (If "the usual escape characters" are some other set, more
specific identification would be appreciated.) (Or if "are interpreted" means something
other than I am understanding it to mean.)
1.3.6 EscapeSequences
The following escape sequences are recognized in character and string literals.
\b \u0008: backspace BS
\t \u0009: horizontal tab HT
\n \u000a: linefeed LF
\f \u000c: form feed FF
\r \u000d: carriage return CR
\" \u0022: double quote "
\’ \u0027: single quote ’
\\ \u005c: backslash \
Okay, skipping \b since I get a '?' for it:
scala> "\t\n\f\r\"\'\\"
res6: String =
"
"'\"
scala> s"\t\n\f\r\"\'\\"
<console>:1: error: unclosed character literal
s"\t\n\f\r\"\'\\"
^
<console>:1: error: unclosed string literal
s"\t\n\f\r\"\'\\"
^
// Removing the \" is enough for it to compile - and produce the same string
scala> s"\t\n\f\r\'\\"
res7: String =
"
'\"
So I think there is one bug here, or there are six bugs here, or the specification is misleading me. I'll throw in this one for good measure, just trying to see if \ is one of the usual escape characters.