Skip to content

Commit 0c57efc

Browse files
committed
string-interpolation: the raw-interpolator also performs variable substitution
Clarify that the raw-interpolator also performs variable substitution. This was not obvious from the text and it is easy to believe that raw means just that: the raw string, as is, without any substitutions performed. This also moves the last sentence of the raw-interpolator section into the following section, where it logicaly belongs.
1 parent 0f0ade0 commit 0c57efc

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

_overviews/scala3-book/string-interpolation.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,22 @@ res1: String = a\nb
211211

212212
The raw interpolator is useful when you want to avoid having expressions like `\n` turn into a return character.
213213

214-
In addition to the three default string interpolators, users can define their own.
214+
Furthermore, the raw interpolator allows the usage of variables, which are replaced with their value, just as the s interpolator.
215+
216+
{% tabs example-11 %}
217+
{% tab 'Scala 2 and 3' for=example-11 %}
218+
```scala
219+
scala> val foo = 42
220+
scala> raw"a\n$foo"
221+
res1: String = a\n42
222+
```
223+
{% endtab %}
224+
{% endtabs %}
215225

216226
## Advanced Usage
217227

228+
In addition to the three default string interpolators, users can define their own.
229+
218230
The literal `s"Hi $name"` is parsed by Scala as a _processed_ string literal.
219231
This means that the compiler does some additional work to this literal. The specifics
220232
of processed strings and string interpolation are described in [SIP-11][sip-11], but
@@ -224,8 +236,8 @@ here's a quick example to help illustrate how they work.
224236

225237
In Scala, all processed string literals are simple code transformations. Anytime the compiler encounters a processed string literal of the form:
226238

227-
{% tabs example-11 %}
228-
{% tab 'Scala 2 and 3' for=example-11 %}
239+
{% tabs example-12 %}
240+
{% tab 'Scala 2 and 3' for=example-12 %}
229241
```scala
230242
id"string content"
231243
```

0 commit comments

Comments
 (0)