Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement interpolation of @things.with.postcircumfix.<at>[the]('end') in interpolating strings #610

Closed
p6rt opened this issue Jan 11, 2009 · 23 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jan 11, 2009

Migrated from rt.perl.org#62198 (status was 'resolved')

Searchable as RT62198$

@p6rt
Copy link
Author

p6rt commented Aug 22, 2008

From @clintongormley

my @​a = < 1 2 3 >;
say "@​a[]";

"@​a[]"

Broken in version 29834

clint

@p6rt
Copy link
Author

p6rt commented Aug 22, 2008

From @moritz

On Fri Aug 22 07​:04​:59 2008, DrTech wrote​:

my @​a = < 1 2 3 >;
say "@​a[]";

"@​a[]"

Broken in version 29834

I added failing TODO tests for that (and hash interpolation) to
spectest_regression r30447 r30449.

(Array interpolation was implemented in r15926 btw)

@p6rt
Copy link
Author

p6rt commented Aug 22, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Aug 22, 2008

From @pmichaud

On Fri, Aug 22, 2008 at 07​:05​:00AM -0700, Clinton Gormley wrote​:

my @​a = < 1 2 3 >;
say "@​a[]";

"@​a[]"

Broken in version 29834

Correct, rakudo doesn't yet know how to interpolate arrays
or hashes in double-quoted strings. This requires a change
to the quote expression parser (which may or may not wait
for us to start using more STD.pm-like parsing).

However, curly interpolation *does* currently work, so one can do
the following instead​:

  > my @​a = < 1 2 3 >; say "@​a = {@​a}";
  @​a = 1 2 3

Pm

@p6rt
Copy link
Author

p6rt commented Nov 30, 2008

From @masak

$ ./perl6 -e 'my $a = "oh hai"; say "{$a.uc} -- KTHXBAI"' # works
OH HAI -- KTHXBAI

$ ./perl6 -e 'my $a = "oh hai"; say "$a.uc() -- KTHXBAI"' # should
output the same
oh hai.uc() -- KTHXBAI

<http://perlcabal.org/syn/S02.html#line_2660>

@p6rt
Copy link
Author

p6rt commented Nov 30, 2008

From @pmichaud

On Sun Nov 30 08​:23​:28 2008, masak wrote​:

$ ./perl6 -e 'my $a = "oh hai"; say "{$a.uc} -- KTHXBAI"' # works
OH HAI -- KTHXBAI

$ ./perl6 -e 'my $a = "oh hai"; say "$a.uc() -- KTHXBAI"' # should
output the same
oh hai.uc() -- KTHXBAI

<http://perlcabal.org/syn/S02.html#line_2660>

This one is just a bit tricky, because the quote parser has to know how
to "lookahead" to make sure there's a valid postcircumfix operator at
the end. Rather than try to update the existing quote expression
parser, I'm planning to wait for when we're using STD.pm as the parser.

In the meantime, I recommend using the curlies.

Pm

@p6rt
Copy link
Author

p6rt commented Nov 30, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Nov 30, 2008

@pmichaud - Status changed from 'open' to 'stalled'

@p6rt
Copy link
Author

p6rt commented Jan 9, 2009

From @finanalyst

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.

@p6rt
Copy link
Author

p6rt commented Jan 9, 2009

From @particle

On Fri, Jan 9, 2009 at 02​:31, via RT Richard Hainsworth
<perl6-bugs-followup@​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

~jerry

@p6rt
Copy link
Author

p6rt commented Jan 9, 2009

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jan 9, 2009

From @particle

On Fri, Jan 9, 2009 at 08​:26, Jonathan Scott Duff <perlpilot@​gmail.com> wrote​:

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

On Fri, Jan 9, 2009 at 02​:31, via RT Richard Hainsworth
<perl6-bugs-followup@​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.

ah! thank you for correcting me, i misremembered. "@​x" won't
interpolate in perl 6. "@​x[1]" will, but is currently not implemented
in rakudo. for the meantime, the workaround is to use closure form​:
"{@​x[1]}".

~jerry

@p6rt
Copy link
Author

p6rt commented Jan 9, 2009

From @masak

jerry (>), Richard (>>)​:

Array element interpolation is not listed as something common not
working in Rakudo.

this is a design choice.

...Meaning that it has dependencies to other components in Rakudo
being replaced or improved, not that it won't ever be implemented in
Rakudo. :)

// Carl

@p6rt
Copy link
Author

p6rt commented Jan 9, 2009

From @perlpilot

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

On Fri, Jan 9, 2009 at 02​:31, via RT Richard Hainsworth
<perl6-bugs-followup@​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
perlpilot@​gmail.com

@p6rt
Copy link
Author

p6rt commented Jan 11, 2009

From markus@mnslaker.f9.co.uk

Scalar variables interpolate, but array and hash elements don't​:

msl@​edward​:~$ perl6 -e 'my $a = 1; say "$a"'
1
msl@​edward​:~$ perl6 -e 'my @​a = 1; say "@​a[0]"'
@​a[0]
msl@​edward​:~$ perl6 -e 'my @​a = 1; say "@​a[]"'
@​a[]
msl@​edward​:~$ perl6 -e 'my %h = (one => 1); say %h<one>'
1
msl@​edward​:~$ perl6 -e 'my %h = (one => 1); say %h{"one"}'
1
msl@​edward​:~$ perl6 -e 'my %h = (one => 1); say "%h<one>"'
%h<one>
msl@​edward​:~$ perl6 -e 'my %h = (one => 1); say "%h{"one"}"'
%hone
msl@​edward​:~$ perl6 -v
This is Rakudo Perl 6, revision 35333 built on parrot 0.8.2-devel
for i486-linux-gnu-thread-multi.

Copyright 2006-2008, The Perl Foundation.

msl@​edward​:~$

@p6rt
Copy link
Author

p6rt commented Jan 12, 2009

From @masak

Markus Laker (>)​:

Scalar variables interpolate, but array and hash elements don't​:

msl@​edward​:~$ perl6 -e 'my $a = 1; say "$a"'
1
msl@​edward​:~$ perl6 -e 'my @​a = 1; say "@​a[0]"'
@​a[0]
msl@​edward​:~$ perl6 -e 'my @​a = 1; say "@​a[]"'
@​a[]
msl@​edward​:~$ perl6 -e 'my %h = (one => 1); say %h<one>'
1
msl@​edward​:~$ perl6 -e 'my %h = (one => 1); say %h{"one"}'
1
msl@​edward​:~$ perl6 -e 'my %h = (one => 1); say "%h<one>"'
%h<one>
msl@​edward​:~$ perl6 -e 'my %h = (one => 1); say "%h{"one"}"'
%hone

This is an oft-reported TODO, but one that's stalling on other future
improvements to the quote parser. In the meantime, you can interpolate
arrays and hashes through closures.

$ perl6 -e 'my @​a = 1; say "{@​a[0]}"'
1
$ perl6 -e 'my @​a = 1; say "{@​a}"'
1
$ perl6 -e 'my @​a = 1,2,3; say "{@​a}"'
1 2 3
$ perl6 -e 'my %h = one => 1; say "{%h}"'
one 1

$ perl6 -e 'my %h = one => 1; say "{%h<one>}"'
1
$ perl6 -e 'my %h = one => 1; say "{%h{"one"}}"'
1

HTH,
// Carl

@p6rt
Copy link
Author

p6rt commented Feb 22, 2009

From peter@schwenn.com

Shouldn't


C​:\parrot>perl6 -e "my @​items; @​items=( 1,2,3,4); say qq(move @​items[] to
you);"

move @​items[] to you


have produced
"move 1234 to you"

If not, how WOULD one provide an interpolating quote context inside of a
perl6 -e ?

ps. this is parrot and rakudo as of Feb 22 morning, (but rakudo has behaved
like this for some time)

@p6rt
Copy link
Author

p6rt commented Feb 23, 2009

From @masak

On Sun Feb 22 11​:46​:09 2009, schwenn wrote​:

Shouldn't


C​:\parrot>perl6 -e "my @​items; @​items=( 1,2,3,4); say qq(move @​items[]
to
you);"

move @​items[] to you


have produced
"move 1234 to you"

Yes. This is a long-standing TODO in Rakudo, awaiting some quoting
redesign, IIRC.

If not, how WOULD one provide an interpolating quote context inside of
a
perl6 -e ?

$ perl6 -e 'my @​items = 1..4; say qq(move {@​items} to you)'
move 1 2 3 4 to you
$

@p6rt
Copy link
Author

p6rt commented Feb 23, 2009

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Apr 15, 2010

From @jnthn

On Fri Aug 22 15​:34​:38 2008, pmichaud wrote​:

On Fri, Aug 22, 2008 at 07​:05​:00AM -0700, Clinton Gormley wrote​:

my @​a = < 1 2 3 >;
say "@​a[]";

"@​a[]"

Broken in version 29834

Correct, rakudo doesn't yet know how to interpolate arrays
or hashes in double-quoted strings. This requires a change
to the quote expression parser (which may or may not wait
for us to start using more STD.pm-like parsing).

We're now using the more STD.pm-like parsing, and this all works nicely.
:-) Turned on the tests too.

Thanks,

Jonathan

1 similar comment
@p6rt
Copy link
Author

p6rt commented Apr 15, 2010

From @jnthn

On Fri Aug 22 15​:34​:38 2008, pmichaud wrote​:

On Fri, Aug 22, 2008 at 07​:05​:00AM -0700, Clinton Gormley wrote​:

my @​a = < 1 2 3 >;
say "@​a[]";

"@​a[]"

Broken in version 29834

Correct, rakudo doesn't yet know how to interpolate arrays
or hashes in double-quoted strings. This requires a change
to the quote expression parser (which may or may not wait
for us to start using more STD.pm-like parsing).

We're now using the more STD.pm-like parsing, and this all works nicely.
:-) Turned on the tests too.

Thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented Apr 15, 2010

@jnthn - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Apr 15, 2010

@jnthn - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Apr 15, 2010
@p6rt p6rt added the Todo label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant