Skip to content

Commit 92e70ee

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 92e70ee

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

_overviews/scala3-book/string-interpolation.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,21 @@ 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+
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+
val foo = 42
220+
221+
scala> raw"a\n$foo"
222+
res1: String = a\n42
223+
```
224+
{% endtab %}
225+
{% endtabs %}
226+
227+
## Advanced Usage
228+
214229
In addition to the three default string interpolators, users can define their own.
215230

216231
## Advanced Usage
@@ -224,8 +239,8 @@ here's a quick example to help illustrate how they work.
224239

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

227-
{% tabs example-11 %}
228-
{% tab 'Scala 2 and 3' for=example-11 %}
242+
{% tabs example-12 %}
243+
{% tab 'Scala 2 and 3' for=example-12 %}
229244
```scala
230245
id"string content"
231246
```

0 commit comments

Comments
 (0)