On Dec 20, 2007 1:48 AM, Michael G Schwern <[EMAIL PROTECTED]> wrote:
> I was reading an article about Perl 6, I forget which one, and it happened to
> mention that code can be interpolated inside double quoted strings.  That's
> one thing, my concern is with the selected syntax.
>
>         say "foo { 1+1 }";   # "foo 2"
>
> The {...} construct seems far too common one in normal text to be given
> special meaning.  One data point is to do a google code search for "{ in Perl
> 5.  It comes up with quite a lot.
> http://www.google.com/codesearch?hl=en&lr=&q=%5C%22%5C%7B+lang%3Aperl&btnG=Search
>
> Another concern is embedded YAML.
>
>         $yaml = "{ $key: 42 }";   # syntax error in Perl 6
>
> Finally, it chokes on unbalanced braces adding another trap for users.
>
> I'm concerned this will lead to a lot of unsightly backwhacking or having to
> be more careful about what type of string you're using.
>
> What about ${} and @{} instead?  ${} would execute in scalar context and @{}
> in list.  They're just cleaned up versions of the successful, but ugly, Perl 5
> idioms ${\(...)} and @{[...]} idioms.  They make use of an existing
> interpolated character so there's no additional load on the programmer.
>
> ${} and @{} already have interpolated meanings in Perl 5 but not in Perl 6.

I am not quite sure of all the implications in the design of quoting
constructs (which is detailed in Synopsis 02 -
http://perlcabal.org/syn/S02.html). But it seems Larry anticipated
mechanisms to handle all the cases you mentioned.

For instance, while {...} expressions do interpolate by default as in

>         say "foo { 1+1 }";   # "foo 2"

but that can be stopped by using a quoting construct plus an adverb. I
think that should be something like

            say Q :!c <foo { 1 + 1}>;   # "foo { 1 + 1 }"

Also, the sigils can interpolate just the way you said, but using ()
rather than braces (which is consistent to how they are used in other
expressions of the language).

It is all there somewhere in Section "Literals" of Synopsis 02
(http://perlcabal.org/syn/S02.html#Literals). More specifically, look
for the item that starts with "In addition to q and qq, there is now
the base form Q".

Kind regards,
Adriano Ferreira

> --
> ...they shared one last kiss that left a bitter yet sweet taste in her
> mouth--kind of like throwing up after eating a junior mint.
>     -- Dishonorable Mention, 2005 Bulwer-Lytton Fiction Contest
>            by Tami Farmer
>
>

Reply via email to