Stream: beginners

Topic: String interpolation with "\(var)" instead of "$(var)"?


view this post on Zulip Ian McLerran (Oct 07 2024 at 19:02):

Since when is "\(var)" valid string interpolation?

I have been playing with AI agents writing roc code by piping in the tutorial, and have discovered that Claude likes to write "\() for string interpolation, and it works!

This is not mentioned as valid syntax in the tutorial, but I have seen Claude write this repeatedly, and to my surprise it actually interpolates the value, and the \ is not printed.

view this post on Zulip Jasper Woudenberg (Oct 07 2024 at 19:12):

String interpolation syntax used to be "\(var)", and recently support was added for "$(var)", I believe because it's better known. The old syntax is still around, I imagine at some point we'll remove it.

view this post on Zulip Richard Feldman (Oct 07 2024 at 19:33):

that's right

view this post on Zulip Richard Feldman (Oct 07 2024 at 19:33):

the reason was more because it gets hard to read in the common case where you're using it with slashes, e.g. in a file path "foo/\(name)/bar" vs. "foo/$(name)/bar"

view this post on Zulip Richard Feldman (Oct 07 2024 at 19:34):

also it was annoying for some vim keybindings

view this post on Zulip Ian McLerran (Oct 07 2024 at 19:46):

Ahh.. Thanks! That makes total sense.

view this post on Zulip Notification Bot (Oct 07 2024 at 19:46):

Ian McLerran has marked this topic as resolved.

view this post on Zulip Luke Boswell (Oct 07 2024 at 20:21):

We should make an issue to track that and remove it. I think it's probably ok to remove already, as it's been a while.

view this post on Zulip Richard Feldman (Oct 07 2024 at 22:08):

agreed!

view this post on Zulip Richard Feldman (Oct 07 2024 at 22:08):

only argument I can see against it is if we want to wait until an 0.1 release to remove it

view this post on Zulip Richard Feldman (Oct 07 2024 at 22:09):

so that like "pre-0.1 Roc" Advent of Code solutions still work

view this post on Zulip Notification Bot (Oct 07 2024 at 22:34):

Ian McLerran has marked this topic as unresolved.

view this post on Zulip Brendan Hansknecht (Oct 07 2024 at 23:11):

"pre-0.1 Roc" Advent of Code solutions still work

Those probably are broken already anyway. Task as builtin, basic cli changes, etc

view this post on Zulip Sam Mohr (Oct 07 2024 at 23:27):

I agree with Brendan. For breaking changes until we reach some 0.1 more "stable" version of Roc, we should try to provide backwards-compatible changes (like Agus' new header syntax that re-formats the old syntax to the new one), and just make announcements for breaking changes like the Task changes. Otherwise, there are gonna be a lot of breaking changes soon (purity inference, try vs ?, etc.) that will be slowed down trying to think of breaking code less than it is already broken.

view this post on Zulip Richard Feldman (Oct 07 2024 at 23:43):

fair point!

view this post on Zulip Oskar Hahn (Oct 08 2024 at 06:08):

Brendan Hansknecht said:

"pre-0.1 Roc" Advent of Code solutions still work

Those probably are broken already anyway. Task as builtin, basic cli changes, etc

Don't forget about Nat. I think this is the main reason, that none of the old AoC files work anymore

view this post on Zulip Luke Boswell (Oct 08 2024 at 06:43):

FWIW I like to go back and update my AoC examples before Dec so people have some working examples. I did it last year and it was really interesting to see how much had changed in only 1 year. :smiley:

view this post on Zulip Luke Boswell (Oct 08 2024 at 07:00):

Luke Boswell said:

We should make an issue to track that and remove it. I think it's probably ok to remove already, as it's been a while.

Issue logged https://github.com/roc-lang/roc/issues/7148


Last updated: Jul 06 2025 at 12:14 UTC