Zulip Chat Archive

Stream: general

Topic: escaping `{` in interpolated strings


Jason Gross (Feb 28 2025 at 20:37):

Is there a way to get curly braces in interpolated strings? In python I'd write f"{{{foo}}}stuff" to get foo + "stuff", but this doesn't seem to work in Lean with s!"{{{foo}}}stuff"? And https://lean-lang.org/doc/reference/latest//Basic-Types/Strings/#string-interpolation doesn't seem to mention anything

Eric Wieser (Feb 28 2025 at 20:42):

s!"{foo}stuff" should mean the same thing as foo + "stuff"

Jason Gross (Feb 28 2025 at 20:43):

Oops, I meant to say that I wanted to know how to get "{" + foo + "}" + stuff

Eric Wieser (Feb 28 2025 at 20:44):

I guess{"{"} works

Thomas Murrills (Feb 28 2025 at 20:45):

s!"\{{foo}}stuff" works too, I believe (assuming you still want to interpolate foo, right?)

Jason Gross (Feb 28 2025 at 20:49):

Thank you! It seems that s!"\{{foo}}stuff works but the VSCode syntax highlighter doesn't highlight it correctly?

Thomas Murrills (Feb 28 2025 at 20:51):

Ooh, that's true...

For anyone who wants to see, here it is on web:

import Lean
run_cmd Lean.logInfo s!"\{{1+1}}"

image.png


Last updated: May 02 2025 at 03:31 UTC