Stream: t-lang

Topic: s#"Hello"


kennytm (Apr 30 2020 at 20:09, on Zulip):

pnkfelix said:
in this case literals that take the structure of String rather than &'static str

i don't follow, `"Hello"s` currently produces a "suffixes on a string literal are invalid" error and there's so "structure" at parse time for the literal "Hello". i don't see a difference of playground-ness between `"Hello"s` and `s#"Hello"`
pnkfelix (Apr 30 2020 at 20:11, on Zulip):

look, I'm just trying to infer what @scottmcm might have meant when they were saying ''' s"Hello" for Strings ''', and I'm basing it on old conversations where people complains that they could not write a literal expression that evaluated to a String value

pnkfelix (Apr 30 2020 at 20:12, on Zulip):

people in the past complained about having to do "foo".into<String>() or whatever

pnkfelix (Apr 30 2020 at 20:13, on Zulip):

/me once again is faced with the reality that they in fact cannot read minds

scottmcm (Apr 30 2020 at 20:42, on Zulip):

I agree that "Hello"s breaks at lex time. Here's the thing that doesn't;

macro_rules! demo {
    ($i:ident # $e:literal ) => {
        ()
    }
}

fn main() {
    demo!(s#"hello");
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f3fa43180f4b61d04a54df78faaaf1c8

scottmcm (Apr 30 2020 at 20:43, on Zulip):

You can do similar things with b"Hello" (one token) vs g"Hello" (two tokens)

scottmcm (Apr 30 2020 at 20:44, on Zulip):

So in order to have a prefix marker for String instead of &str -- like we have for getting [u8; N] instead of &str -- then it's a breaking change unless we reserve lexical space

mark-i-m (Apr 30 2020 at 20:46, on Zulip):

Oh, s"Hello": String would be awesome! Can we do this over an edition?

scottmcm (Apr 30 2020 at 20:47, on Zulip):

Yes, as far as I know, since it's frontend-only.

kennytm (Apr 30 2020 at 20:47, on Zulip):

a prefix marker would conflict with raw strings though, unlike r"2 \ge 1"s.

kennytm (Apr 30 2020 at 20:48, on Zulip):

(you could make it sr"2 \ge 1" for sure)

mark-i-m (Apr 30 2020 at 20:49, on Zulip):

What does the r mean? is that already rust syntax?

kennytm (Apr 30 2020 at 20:49, on Zulip):

yes

kennytm (Apr 30 2020 at 20:49, on Zulip):
fn main() {
    dbg!(r"2 \ge 1"); // [src/main.rs:2] r"2 \ge 1" = "2 \\ge 1"
}
mark-i-m (Apr 30 2020 at 20:50, on Zulip):

lol, I already knew that :face_palm:

pnkfelix (Apr 30 2020 at 20:50, on Zulip):

Part of what I've been confused about in this conversation is that the s suffix on @kennytm 's examples is not a typo nor a plural; its the whole point they are making

scottmcm (Apr 30 2020 at 20:50, on Zulip):

I don't think a prefix marker conflicts if it's language syntax, since there's already br##"hello"##

pnkfelix (Apr 30 2020 at 20:50, on Zulip):

i.e. a suffix marker

scottmcm (Apr 30 2020 at 20:50, on Zulip):

So sr#"hello"# would also work

kennytm (Apr 30 2020 at 20:51, on Zulip):

yes. (one disadvantage is that the plain prefix can't end with r :upside_down:)

scottmcm (Apr 30 2020 at 20:51, on Zulip):

Now, if the idea was that suffixes would be a new extensability point -- like C++'s custom literals -- then something that's not a prefix might be better, i agree

pnkfelix (Apr 30 2020 at 20:51, on Zulip):

s##"hello to all the #as#es "## would work as well, right?

Josh Triplett (Apr 30 2020 at 20:52, on Zulip):

mark-i-m said:

What does the r mean? is that already rust syntax?

We started out with raw string syntax, for r#"foo"#, and then we introduced raw identifier syntax using r#not_a_keyword (which didn't conflict because it doesn't start with r#"), and now we're thinking about using the same lexing space for "raw language constructs, without surface syntax", using r#$something, which again wouldn't conflict with anything that lexes today.

mark-i-m (Apr 30 2020 at 20:52, on Zulip):

Ah, hmm. Yes, I see the point now.

scottmcm (Apr 30 2020 at 20:52, on Zulip):

@pnkfelix I don't know -- does b##"hello to all the #as#es "## work? I thought it needed the r

pnkfelix (Apr 30 2020 at 20:53, on Zulip):

pnkfelix said:

s##"hello to all the #as#es "## would work as well, right?

(assuming we went with scott's suggestion that we should eagerly reserve <ident> # <stuff>)

pnkfelix (Apr 30 2020 at 20:53, on Zulip):

@scottmcm hmm I guess I was just assuming that was "simply a matter of engineering"

pnkfelix (Apr 30 2020 at 20:54, on Zulip):

/me is sad that they forgot to write their message as the more simply put s##"#ello"##

scottmcm (Apr 30 2020 at 20:54, on Zulip):

Fair point. I guess I'm mixing "would it be reserved" vs "is that how we'd do it", which are different questions.

Agreed that that would be reserved.

Last update: Jun 05 2020 at 22:50UTC