'Subroutine calls' mentions that return there is no special cases for return, but it does not seem possible.
For example:
foo(1, return(2, 3), 4);
If return is not special and treated like any other subroutine, it will be possible to use it in an expression. If return was a subroutine, it would get arguments (2, 3), so under these rules the snippet above should return (2, 3) as well. But in perl this returns (2, 3, 4) because return consumes everything until the last closing parenthesis.
One way or another return needs to be special. Some options are:
1) only allow return as a stand-alone statement with a pair of top-level parenthesis around arguments.
return(1, 2); # ok
return(1, 2), 3; # not ok
return(@foo); # ok
return @foo; #not ok
foo(1, return 2); # not ok
(package keyword is not allowed in expressions, so it seems there is precedent for stand-alone statement operators like this already).
2) only allow return as a stand-alone statement, but accept full syntax:
return (1, 2), 3; # ok
return @foo; # ok
foo(1, return 2) # not ok
3) don't restrict use of return in any way:
foo(1, return 2) # ok
foo(1, return (2, 3), 4) # ok
'Subroutine calls' mentions that
return
there is no special cases for return, but it does not seem possible.For example:
If
return
is not special and treated like any other subroutine, it will be possible to use it in an expression. Ifreturn
was a subroutine, it would get arguments(2, 3)
, so under these rules the snippet above should return(2, 3)
as well. But in perl this returns (2, 3, 4) becausereturn
consumes everything until the last closing parenthesis.One way or another return needs to be special. Some options are:
1) only allow
return
as a stand-alone statement with a pair of top-level parenthesis around arguments.(
package
keyword is not allowed in expressions, so it seems there is precedent for stand-alone statement operators like this already).2) only allow
return
as a stand-alone statement, but accept full syntax:3) don't restrict use of
return
in any way: