sharkdp / numbat

A statically typed programming language for scientific computations with first class support for physical dimensions and units
https://numbat.dev
Apache License 2.0
1.26k stars 53 forks source link

Add support for raw strings #442

Open triallax opened 5 months ago

triallax commented 5 months ago

This ticket requests adding support for raw strings, inside of which usually special syntax such as string interpolations would be treated as literal parts of the string. Possible forms we could add:

I think the Rust syntax is pretty nice because you can add as many #'s as needed to disambiguate the end of the string from its contents (and also because we usually do things the Rust way in Numbat :D).

sharkdp commented 5 months ago

I'm fine with adding raw strings to the language eventually. But I'm questioning if this is the right time? Do we have concrete use cases for raw strings?

I tend to use them in unit tests if my code handles large blocks of text (that I want to copy in from somewhere). For smaller strings, I'm usually okay with escaping things by hand.

eminence commented 5 months ago

I think this might have come from a request I made in IRC. I wanted to use numbat to calculate the length of a string, but I couldn't do because the string contained { and } characters.

triallax commented 5 months ago

That was what made me think about the issue yeah, but @sharkdp is right that, at least for now, this isn't really important because there aren't any major concrete use cases for it at the moment.

sharkdp commented 5 months ago

I couldn't do because the string contained { and } characters.

I remembered the conversation, but not this use case. Given that we don't have Python-style f"…" strings for using formatters, it might be nice to have raw strings after all. I'd say it's okay to implement them now if they don't add too much complexity.