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

where clause thunk's return value used for smartmatching #6212

Closed
p6rt opened this issue May 1, 2017 · 6 comments
Closed

where clause thunk's return value used for smartmatching #6212

p6rt opened this issue May 1, 2017 · 6 comments

Comments

@p6rt
Copy link

@p6rt p6rt commented May 1, 2017

Migrated from rt.perl.org#131239 (status was 'rejected')

Searchable as RT131239$

@p6rt
Copy link
Author

@p6rt p6rt commented May 1, 2017

From @zoffixznet

I expected these two forms to behave the same​:

  <Zoffix_> m​: my $ where .so && .name = sub foo {}
  <camelia> rakudo-moar a2602b​: OUTPUT​: «Sub object coerced to string (please use .gist or .perl to do that)␤ in block <unit> at <tmp> line 1␤»
  <Zoffix_> m​: my $ where { .so && .name } = sub foo {}
  <camelia> rakudo-moar a2602b​: ( no output )

However, it looks like in the thunk form, the return value of the thunk is then smart matched against the original value.

Loading

@p6rt
Copy link
Author

@p6rt p6rt commented May 1, 2017

From @zoffixznet

On Sun, 30 Apr 2017 17​:11​:08 -0700, cpan@​zoffix.com wrote​:

I expected these two forms to behave the same​:

<Zoffix_> m​: my $ where .so && .name = sub foo {}
<camelia> rakudo-moar a2602b​: OUTPUT​: «Sub object coerced to string
(please use .gist or .perl to do that)␤ in block <unit> at <tmp> line
1␤»
<Zoffix_> m​: my $ where { .so && .name } = sub foo {}
<camelia> rakudo-moar a2602b​: ( no output )

However, it looks like in the thunk form, the return value of the
thunk is then smart matched against the original value.

Well, I fixed this bug!.... and then realized it's not even a bug.

The behaviour without the block is correct​: when checking, the thunk calls .so and then .name, and the return value of that gets smartmatched agains. This is the same as what we do with `when` clauses.

The correct way to write that would be to use `&`.

Loading

@p6rt p6rt closed this May 1, 2017
@p6rt
Copy link
Author

@p6rt p6rt commented May 1, 2017

@zoffixznet - Status changed from 'new' to 'rejected'

Loading

@p6rt
Copy link
Author

@p6rt p6rt commented May 1, 2017

From @zoffixznet

On Sun, 30 Apr 2017 18​:47​:16 -0700, cpan@​zoffix.com wrote​:

The correct way to write that would be to use `&`.

And .so on .name

Loading

@p6rt
Copy link
Author

@p6rt p6rt commented May 1, 2017

From 1parrota@gmail.com

If Zoffix gets this confused, maybe the explanation needs some work
for mere mortals?

On 4/30/17, Zoffix Znet via RT <perl6-bugs-followup@​perl.org> wrote​:

On Sun, 30 Apr 2017 18​:47​:16 -0700, cpan@​zoffix.com wrote​:

The correct way to write that would be to use `&`.

And .so on .name

Loading

@p6rt
Copy link
Author

@p6rt p6rt commented May 1, 2017

From @zoffixznet

On Mon, 01 May 2017 10​:15​:03 -0700, 1parrota@​gmail.com wrote​:

If Zoffix gets this confused, maybe the explanation needs some work
for mere mortals?

Added a note to docs in Raku/doc@8016512

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant