HaloO,

Tim Bunce wrote:
On Sun, Jan 11, 2009 at 04:41:12PM -0800, Ovid wrote:
I really don't think this is a bug, but it did confuse the heck out of me at 
first.  This *is* expected behavior due to how {} is interpolated in strings, 
yes?

  $ perl6 -e 'my $foo = "foo";say "<" ~ $foo ~ ">"'
  <foo>
  $ perl6 -e 'my $foo = "foo";say "{" ~ $foo ~ "}"'
~ foo ~

I presume string interpolation is, er, "set-up", at compile-time.
So it only happened here because "{" ~ $foo ~ "}" was rewritten to
"{$foo}" at compile-time.  And if "{" and "}" were replaced with
variables, for example, then the interpolation wouldn't have happened.
Right?

The point is that the code that is interpolated is just the
string " ~ $foo ~ " which is interpolated when the closure runs.
That is there are two nested interpolations! Note that you can't
use "{" to initialize a variable because it either ends in a syntax
error or as in the given example swallows some code into a string.
This works as you intent:

   my $left = '{';
   my $right = '}';
   my $foo = "foo"; # no danger with interpolation

   say $left ~ $foo ~ $right;

That is in the example from Ovid there are *no* concatenations!


Regards, TSa.
--

"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
"Simplicity does not precede complexity, but follows it." -- A.J. Perlis
1 + 2 + 3 + 4 + ... = -1/12  -- Srinivasa Ramanujan

Reply via email to