C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Supporting f-strings in C++: draft-R1

From: Chris Gary <cgary512_at_[hidden]>
Date: Sun, 15 Oct 2023 17:54:59 -0600
Just some thoughts:

I find it strange that the "{}" syntax was adopted instead of
some variation on "%" or "introducer-then-parameters" instead of "scoped
parameters".

The former requires single-scope balancing, whereas the latter can be
matched with a regular expression (depending on what is allowed), and is
easier to validate.

Depending on what format() is being used, I find "%%" meaning a percent
sign easier to read than "{{}" or "\{" (or really "\\{") meaning a
curly brace was intended.
I don't often type "%" in text literally and it tends to stand out.

In either case, arguments devoid of parameters take only two tokens; "{}"
and then something like "%@" are unambiguous.
I also find "@" easier to spot in a language where it isn't often used
elsewhere as opposed to even more curly braces.
They mean the same thing otherwise - both type-safe as interpreted and
refer to an argument to be replaced.

The Python style works in Python, and is readable there, because there
isn't already a proliferation of similar-looking tokens.

It also seems as though syntactical limitations inherent to finding
arbitrary tokens in string literals are presenting themselves as more
cognitive overhead for the reader, despite the apparent scoping of
parameters within a "{}". Intuition suggests that, wherever a variable may
be used, then so can an expression (a scalar is just a one-element
expression).

On Sun, Oct 15, 2023 at 5:19 AM Hadriel Kaplan via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> I've posted a second revision of the draft here:
> https://tinyurl.com/y7av5tbw
>
> This incorporates some of the feedback, adds some more details, and
> proposes the two separate types: f-strings and x-strings, with f-string
> just being sugar for `std::format(X"...")`.
>
> Thanks for the feedback - I think it really improved the proposal.
>
> -hadriel
>
>
> > From: Hadriel Kaplan <hkaplan_at_[hidden]>
>
> > OK, then how about compromise-B: two prefixes...
> > Let X"" expand this:
> > X"{prefix}_{name}: got {calculate()} for {bits:#06x}"
> > To this:
> > "{}_{}: got {} for {:#06x}", prefix, name, calculate(), bits
> > And let F"" expand this:
> > F"{prefix}_{name}: got {calculate()} for {bits:#06x}"
> > To this:
> > std::format("{}_{}: got {} for {:#06x}", prefix, name, calculate(),
> bits)
> > And obviously we could specify F"" as just being `::std::format(X"")`
> internally.
>
>
>
>
>
> Juniper Public
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2023-10-15 23:55:12