Skip to content

Commit b5cf5f8

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 b5cf5f8

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

_overviews/scala3-book/string-interpolation.md

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

216230
## Advanced Usage
@@ -224,8 +238,8 @@ here's a quick example to help illustrate how they work.
224238

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

227-
{% tabs example-11 %}
228-
{% tab 'Scala 2 and 3' for=example-11 %}
241+
{% tabs example-12 %}
242+
{% tab 'Scala 2 and 3' for=example-12 %}
229243
```scala
230244
id"string content"
231245
```

0 commit comments

Comments
 (0)