On Fri, Jan 9, 2009 at 9:49 AM, jerry gay <jerry....@gmail.com> wrote:

> On Fri, Jan 9, 2009 at 02:31, via RT Richard Hainsworth
> <perl6-bugs-follo...@perl.org> wrote:
> > # New Ticket Created by  Richard Hainsworth
> > # Please include the string:  [perl #62116]
> > # in the subject line of all future correspondence about this issue.
> > # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=62116 >
> >
> >
> > Array element does not interpolate it does in perl5
> > (Is this a design choice or a rakudo bug?)
> >
> > $ perl6
> >  > my @x=(1,2,3); say "2nd is @x[1]"
> > 2nd is @x[1]
> >
> > $ zoid
> > --[ This is the Zoidberg shell ]--[ Version 0.96 ]--
> > ### This is a development version, consider it unstable
> > $ @x=(1,2,3);print "2nd is $x[1]\n";
> > 2nd is 2
> >
> > Array element interpolation is not listed as something common not
> > working in Rakudo.
> >
> this is a design choice. in order to interpolate this, use a closure
> inside the string.
> my @x = 1, 2, 3; say "2nd is {...@x[1]}"; # 2nd is 2


Er ... that may be a temporary rakudo design choice, but S02 says:

Bare scalar variables always interpolate in double-quotish

strings.  Bare array, hash, and subroutine variables may I<never> be
interpolated.  However, any scalar, array, hash or subroutine variable may

start an interpolation if it is followed by a sequence of one or more bracketed

dereferencers: that is, any of:

=over 4

=item 1. An array subscript

=item 2. A hash subscript

=item 3. A set of parentheses indicating a function call

=item 4. Any of 1 through 3 in their B<dot> form

=item 5. A method call that includes argument parentheses

=item 6. A sequence of one or more unparenthesized method call,
followed by any of 1 through 5

=back

In other words, this is legal:

    "Val = $a.ord.fmt('%x')\n"

and is equivalent to

    "Val = { $a.ord.fmt('%x') }\n"


So, it would seem that

my @x = 1, 2, 3; say "2nd is @x[1]"; # 2nd is 2

is perfectly valid perl 6.

-Scott
-- 
Jonathan Scott Duff
perlpi...@gmail.com

Reply via email to