[Suggestion] Allow string literals (e.g., in map["key"]) within interpolation expressions
Motivation / Problem
Currently, the official documentation states that string interpolation expressions (\{...}) cannot contain double quotes (").
This is a reasonable limitation, but it makes a very common and intuitive programming pattern—interpolating a map value accessed by a string key—feel cumbersome. To achieve this, developers must create a temporary variable, which adds boilerplate code and makes the intent less direct.
For example, this highly intuitive code is currently disallowed:
// This code feels natural, but fails due to the `"` limitation.
fn main() {
let my_map = Map::of([("key", 123)])
println("The value is: \{my_map["key"]}")
}
The required workaround is to use a temporary variable, which is less ergonomic:
// This works, but is less direct.
fn main() {
let my_map = Map::of([("key", 123)])
let value = my_map["key"]
println("The value is: \{value}")
}
try.moonbitlang.com/#7b99eeb7
This is a reasonable limitation, but it makes a very common and intuitive programming pattern—interpolating a map value accessed by a string key—feel cumbersome.
Allowing " in the interpolation will complicate the lexer and error recovery in the parser, but it is a compelling argument. @bobzhang