Stream: beginners

Topic: string interpolation


view this post on Zulip Nick Hallstrom (Feb 09 2023 at 20:52):

Is there plan to support expressions in string interpolation? For example, I would expect this to work:

"I have \(Num.toStr(2)) apples"

But I get I was expecting an identifier, like \u(message) or \u(LoremIpsum.text).

view this post on Zulip Brian Carroll (Feb 09 2023 at 21:02):

I believe it's a deliberate choice designed to avoid large expressions in interpolated strings which can be hard to read in other languages.
The idea being that if it doesn't work out well it's easy to relax the rules later. But it's hard to start relaxed and make them stricter later.

view this post on Zulip Nick Hallstrom (Feb 09 2023 at 21:14):

Gotcha, that makes sense. Is there plan to add an ability similar to the Display trait in Rust? Then you could avoid complex expressions but still allow something like "I have \(2) apples".

view this post on Zulip Brendan Hansknecht (Feb 09 2023 at 22:52):

yes

view this post on Zulip Brendan Hansknecht (Feb 09 2023 at 22:53):

It has been discussed a few times and is almost certainly something we want to add in the future


Last updated: Jul 05 2025 at 12:14 UTC