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

Implicitly returning nothing from a subroutine returns an empty container #4533

Closed
p6rt opened this issue Sep 13, 2015 · 5 comments
Closed

Comments

@p6rt
Copy link

p6rt commented Sep 13, 2015

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

Searchable as RT126049$

@p6rt
Copy link
Author

p6rt commented Sep 13, 2015

From @thundergnat

Post GLR, implicitly returning nothing from a subroutine now returns an
empty container. Becomes a problem when assigning to an array as it now
ends up containing an element even if none was returned.

  perl6 -e' sub h () { return }; my @​p = h(); say @​p, so @​p '
  [(Any)]True

  perl6 -e' sub h () { }; my @​p = h(); say @​p, so @​p '
  [(Any)]True

Now if you want to return nothing, you need to do it explicitly.

  perl6 -e' sub h () { return () }; my @​p = h(); say @​p, so @​p '
  []False

  perl6 -e' sub h () { () }; my @​p = h(); say @​p, so @​p '
  []False

Could be argued that it isn't a bug, but it is surprising to me and is
different from pre GLR behaviour.

@p6rt
Copy link
Author

p6rt commented Sep 23, 2015

@p6rt
Copy link
Author

p6rt commented Sep 24, 2015

From @TimToady

In C culture, a bare return means "This is a procedure, not a function, and I'm not expecting to return anything", and so I think the absence of a meaningful value is properly conveyed by Nil in Perl 6. If the intent of a return is to allow interpolation of Slip or (), then that choice should be made explicit. Nil is a better default because it doesn't accidentally disappear in an unintended list context. In this sense, Nil can be considered the most basic failure value, designed to trip things up downstream if abused.

Roast changes​: Raku/roast@cecbb2a9a7

@p6rt
Copy link
Author

p6rt commented Sep 24, 2015

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

@p6rt p6rt closed this as completed Sep 24, 2015
@p6rt
Copy link
Author

p6rt commented Sep 24, 2015

@TimToady - Status changed from 'open' to 'rejected'

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

No branches or pull requests

1 participant