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

WhateverCode on the LHS of ~~ (trap?) #1603

Closed
AlexDaniel opened this issue Oct 11, 2017 · 1 comment
Closed

WhateverCode on the LHS of ~~ (trap?) #1603

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

Comments

@AlexDaniel
Copy link
Member

A question on #perl6 channel was asked today:

my @a = <1 2 3>; say @a.grep( *.Int ~~ 2 );
Cannot use Bool as Matcher with '.grep'.  Did you mean to use $_ inside a block?
  in block <unit> at <tmp> line 1

why is this? why doesn't this dwim?

Followed by:

<geekosaur> I thought this was a listed/known trap

Yet I don't see it listed on the traps page. We have a similar item there… similar but completely different. That being said, the trick that is mentioned there still applies:

my @a = <1 2 3>; say @a.grep( 2 ~~ *.Int );
(2)

However, more common solution to this is to use a block instead:

my @a = <1 2 3>; say @a.grep( {.Int ~~ 2} );
(2)
@AlexDaniel AlexDaniel added the docs Documentation issue (primary issue type) label Oct 11, 2017
@AlexDaniel AlexDaniel changed the title WhateverCode on the LHF of ~~ (trap?) WhateverCode on the LHS of ~~ (trap?) Oct 11, 2017
@tisonkun
Copy link
Member

tisonkun commented Oct 12, 2017

IMO it's a trap, for
*.Int ~~ 2 equals 2.ACCEPTS(*.Int), and return False
2 ~~ *.Int equals *.Int.ACCEPTS(2) and it is a instance of WhateverCode

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

2 participants