> Hello!
>
> Recently I was coding Perl 5 and quite often I had to change
> interpolated strings or C<print> to C<sprintf> or <printf>.
>
> I began to wonder, if qq strings couldn't allow sprintf-like
> formatting directly.
>
> I could imagine an \F escape sequence with the following syntax:
>
> : '\F' printf-format-without-% '(' expr ')'
> | '\F' printf-format-without-% '{' string '}'
Now, if you're on a Perl 6 list, you'd better be using Perl 6 patterns
:-)
/ \\F <printf_format_without_percent> \( <expr> \)
| \\F <printf_format_without_percent> \( <string> \) /
> Examples:
>
> "The value in hex is \Fx($value)."
> "You currently have \F020d($dollars) on your account."
> "Leave some --\Fs60{space for this $interpolates string}--."
>
> I find this syntax reads very well.
> eg. "The value in hex is 'format hex $value'."
I definitely like the idea. It's something like Python's % operator,
but inline, which seems to make more sense.
As far as the syntax, the () and {} don't make a lot of sense with
regard to the rest of the language. We could either utilize the
string/numeric context distinction that already exists in {} and []
for subscripting, or we could always use () in analog to $().
I'd like to have that dollar in there somewhere, actually.
"The value in hex is \Fx$( expression )."
Or something. That is kinda clunky, though. Maybe just a
stringification adverb, albeit verbose (but more versatile):
"The value in hex is $( expression where format('x') )"
No, I actually think that should be a property. In fact, one that has
been discussed before:
"The value in hex is $( expression but formatted('x') )"
That's actually my favorite so far.
> -Edwin
Luke