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
Some unary functions accept multiple arguments #11540
Comments
From @cpansproutperl56delta has this section: Better syntax checks on parenthesized unary operators print defined(&foo,&bar,&baz); used to be accidentally allowed in earlier versions, and produced The parenthesized forms of most unary operators that expect a single print defined &foo, &bar, &baz; remains unchanged. See perlop. A few of unary functions survived, though: prototype(1,2,3) evaluates 1 and 2 in void context, using 3 (in scalar context) as its argument. That’s harmless, although a bit surprising. eval() behaves the same way. When called in list context readline and readpipe evaluate their arguments in list context, and then pop the topmost item leaving everything else there, in addition to the value intended to be returned. In scalar context readline and readpipe act like prototype. In dynamic context (determined at run-time; e.g., at the end of a sub) readline and readpipe propagate their context to *all* their arguments. So readpipe(foo(),foo()) at the end of a subroutine makes both foo calls in scalar context if the subroutine is called in scalar context, but calls the first foo in void context if readpipe can be determined at compile time to be in scalar context. Here are some examples: $ perl -le'open my $foo, "<", \"bar"; print readline("baz",$foo)' $ perl -le'open my $foo, "<", \"bar"; print "baz",$foo,readline(sub{}->())' Context of readline’s operands: $ perl -le 'sub context { print qw[void scalar list][wantarray + defined wantarray] } readline(context,context)' which means that a function called in void context can return a value (the second readline would give bar, not baz, if get_foo’s retval were ignored): $ perl -le 'open my $foo, "<", \"bar\nbaz"; sub get_foo {print qw[void scalar list][wantarray + defined wantarray]; $foo } readline(get_foo); print scalar readline $foo' $ perl -le 'sub context { print qw[void scalar list][wantarray + defined wantarray] } $x = readline(context,context)' $ perl -le 'sub context { print qw[void scalar list][wantarray + defined wantarray] } () = readline(context,context)' Context of readline’s operands in dynamic context: $ perl -le 'sub context { print qw[void scalar list][wantarray + defined wantarray] } sub { readline(context,context) }->()' $ perl -le 'sub context { print qw[void scalar list][wantarray + defined wantarray] } $x = sub { readline(context,context) }->()' $ perl -le 'sub context { print qw[void scalar list][wantarray + defined wantarray] } () = sub { readline(context,context) }->()' Flags: Site configuration information for perl 5.15.0: Configured by sprout at Thu Jun 16 05:42:17 PDT 2011. Summary of my perl5 (revision 5 version 15 subversion 0) configuration: Locally applied patches: @INC for perl 5.15.0: Environment for perl 5.15.0: |
From @cpansproutOn Sun Jul 31 13:54:42 2011, sprout wrote:
I’ve been thinking about this on and off for some time. !($foo, $bar) evaluates $foo in void context and $bar in scalar context. The same applies to not($foo, $bar) and scalar($foo, $bar). So I’ve been wondering why chr and getprotobynumber (for example) need If I get a void warning when writing scalar(3, foo()), isn’t that Now, there is one case where it makes sense to refuse more than one I’m using the term lvalue in the broad sense of anything that goes In the case of untie(%foo,%bar), it is completely counterintuitive that What I propose we do is make built-in functions with a prototype (or Now, should the laxity regarding ($) apply to user-defined subroutines, too? -- Father Chrysostomos |
From [Unknown Contact. See original ticket]On Sun Jul 31 13:54:42 2011, sprout wrote:
I’ve been thinking about this on and off for some time. !($foo, $bar) evaluates $foo in void context and $bar in scalar context. The same applies to not($foo, $bar) and scalar($foo, $bar). So I’ve been wondering why chr and getprotobynumber (for example) need If I get a void warning when writing scalar(3, foo()), isn’t that Now, there is one case where it makes sense to refuse more than one I’m using the term lvalue in the broad sense of anything that goes In the case of untie(%foo,%bar), it is completely counterintuitive that What I propose we do is make built-in functions with a prototype (or Now, should the laxity regarding ($) apply to user-defined subroutines, too? -- Father Chrysostomos |
@cpansprout - Status changed from 'new' to 'open' |
From @ap* Father Chrysostomos via RT <perlbug-comment@perl.org> [2012-05-12 21:15]:
I’ll turn your question on its head. Is there any reason not to make `scalar` as strict as `chr`? What does We have had a lot of cases where syntax improvements or alterations So all else being equal I would advocate more strictness over less, as Regards, |
Migrated from rt.perl.org#96006 (status was 'open')
Searchable as RT96006$
The text was updated successfully, but these errors were encountered: