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

%h«$x» is a trap #1369

Closed
AlexDaniel opened this issue Jun 7, 2017 · 1 comment
Closed

%h«$x» is a trap #1369

AlexDaniel opened this issue Jun 7, 2017 · 1 comment
Labels
docs Documentation issue (primary issue type) trap

Comments

@AlexDaniel
Copy link
Member

AlexDaniel commented Jun 7, 2017

I've never seen this before, and I'm actually surprised that somebody came up with this (edit: actually, our docs suggested it).

Code:

my %h = ‘hello’ => 42;
my $x = ‘hello’;
say %h«$x»

Result:

42

So it works, right? Wrong.

Code:

my %h = ‘hello world’ => 42;
my $x = ‘hello world’;
say %h«$x»

Result:

((Any) (Any))

Of course, the right way to do it is to use %h{$x}. If you insist on «» for some reason, then %h«“$x”».

See this: https://irclog.perlgeek.de/perl6/2017-06-07#i_14699923

@AlexDaniel AlexDaniel added the docs Documentation issue (primary issue type) label Jun 7, 2017
@AlexDaniel
Copy link
Member Author

OK, this is a pitfall, because our docs are full of this:

doc/Language/5to6-nutshell.pod6:    say %calories«$key»;  # Perl 6 - double angles interpolate as a list of Str
doc/Language/5to6-nutshell.pod6:    say join ',', %calories«$keys»;          # Perl 6 the split is done after interpolation
doc/Language/operators.pod6:    say %color«cherry $fruit».perl;   # OUTPUT: «("red", "green")␤»
doc/Language/rb-nutshell.pod6:    say %calories«$key»;    # Perl 6 - double angles interpolate as double-quotes
doc/Language/rb-nutshell.pod6:    say %calories«$keys».join(','); # Perl 6, interpolated split
doc/Language/subscripts.pod6:    %hash«foo $var»;    # same as %hash{ «foo $var» }
doc/Type/Hash.pod6:    dd %h«oranges $fruit»;

@AlexDaniel AlexDaniel changed the title %h«$x» is a trap, maybe %h«$x» is a trap Jun 7, 2017
AlexDaniel added a commit that referenced this issue Jun 7, 2017
Please revise.

Generally, we shouldn't show wrong usage anyway, but it may be
possible that I misunderstood some of the examples.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation issue (primary issue type) trap
Projects
None yet
Development

No branches or pull requests

1 participant