From b5cf5f892050cb38b92718d8f577be5435fcb978 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 22 Jan 2025 13:13:18 +0100 Subject: [PATCH] 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. --- _overviews/scala3-book/string-interpolation.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/_overviews/scala3-book/string-interpolation.md b/_overviews/scala3-book/string-interpolation.md index e1c4f10054..9743eecbde 100644 --- a/_overviews/scala3-book/string-interpolation.md +++ b/_overviews/scala3-book/string-interpolation.md @@ -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 @@ -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" ```