2 ms·
The article mentions being inspired by Rust syntax, save for 'skipping the ugly “r”', but neglects to mention that the leading r exists so that it's possible to
by kibwen 8y ago
The article mentions being inspired by Rust syntax, save for 'skipping the ugly “r”', but neglects to mention that the leading r exists so that it's possible to have raw strings that have zero hashes at either end. IOW, in Rust, a string that allows escape sequences looks like "foo", and a string that doesn't allow escape sequences looks like r"foo". And note that Rust didn't invent this syntax, but rather took it from Python--though the addition of optional hashes around the string delimiters allows this single syntax to raw-encode not just backslashes, but also double-quotes (which Python has a separate, triply-quoted string syntax for (and which Swift appears to have used to denote multiline strings (which is just the default behavior of all string literals in Rust))).
- chrismorgan 8y agoYes. In the article: > This system was inspired by the Rust programming language. Rust stacks one or more pounds at each end of a string (and prefixes the letter “r”) to create what it calls “raw strings”, that is strings without further escape sequence interpretation. You cannot incorporate interpolation or coded tabs, new lines, or returns. “one or more” should be “zero or more”, and the bit about the “r” prefix shouldn’t be parenthesised, as it’s actually the part that makes it a raw string. Also its mention of interpolation is poor: Rust doesn’t have interpolation on plain string literals, but things like the format!() macro perform what is more or less interpolation on their first argument (which must be a string literal), and raw strings work just fine there.
- richardwhiuk 8y agoThe key thing is that raw strings don't have escape sequences.