Skip to content

Commit

Permalink
string-interpolation: the raw-interpolator also performs variable sub…
Browse files Browse the repository at this point in the history
…stitution

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.
  • Loading branch information
Flowdalic committed Jan 22, 2025
1 parent 0f0ade0 commit b5cf5f8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions _overviews/scala3-book/string-interpolation.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,20 @@ res1: String = a\nb

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

Furthermore, the raw interpolator allows the usage of variables, which are replaced with their value, just as the s interpolator.

{% tabs example-11 %}
{% tab 'Scala 2 and 3' for=example-11 %}
```scala
scala> val foo = 42
scala> raw"a\n$foo"
res1: String = a\n42
```
{% endtab %}
{% endtabs %}

## Advanced Usage

In addition to the three default string interpolators, users can define their own.

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

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

{% tabs example-11 %}
{% tab 'Scala 2 and 3' for=example-11 %}
{% tabs example-12 %}
{% tab 'Scala 2 and 3' for=example-12 %}
```scala
id"string content"
```
Expand Down

0 comments on commit b5cf5f8

Please sign in to comment.