Luke Palmer <[EMAIL PROTECTED]> writes:

> 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 $().

My idea was to make it like the scoped \L{ } of Apocalypse 2.
The \L also says something about formatting and the { } creates a
scope, which "stays" in the interpolated string.

You are right about the (), however, because there should be a
more visible marker (probably a sigil) when the syntax changes from
<interpolated_string> to <expr>.

> I'd like to have that dollar in there somewhere, actually.  
>
>     "The value in hex is \Fx$( expression )."

The problem is calculated format (I forgot to mention this):

      "The value in the chosen format is \F$format$( expression )."

The compiler cannot know, if $format contains the whole format
specifier or just a part (or nothing) so it does not know if it should
take $( expression ) as part of the format or as the formatee ;).

With my proposed syntax the first '(' outside any nesting constructs
would clearly mark the beginning of the formatee.

One option would be to only allow

    \\F <interpolated_without_unnested_open_brace> \{ <string> \}

so this would work and the dollar is there:

    "You wanted to see it like that: \F$format\Q{$that}"
    "You have \F${digits}d{$cent}."

...which is less than beautiful (should not be common, though).
Also the formatee would always be converted to a string before
formatting (also see conclusion below).

> 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.

So the value should 'carry' its own format...This makes sense in some
cases, in other cases it does not (Though you always could override
with another C<but>.)

The syntax is clean, but even longer than with sprintf:

     "The value in hex is $( expression but formatted('x') )"
     "The value in hex is $( sprintf '%x',expression )"

Why not allow both (\F with {} and C<but formatted>)? If we disallow
interpolated formats on the \F it introduces minimal complexity into
the parser and compiler. The only price to pay would be the \F
itself.

Disallowing interpolated formats on \F has the additional advantage of
making the {} unnecessary in the most common cases (also removing the
'force to string').

The best of both worlds:

    sub foo(int $x,int $y)
    {
        # print "fooing $x with $y\n" if $debug;
        # change it to hex format temporarily

        print "fooing \Fx$x with \Fx$y\n" if $debug;
    }

    $msg = "The value of \$y is $( $y but formatted($chosen_format || '0d') )."

-Edwin

Reply via email to