develooper Front page | perl.perl5.porters | Postings from April 2008

prototypes, parsing and optrees

Thread Next
From:
Nicholas Clark
Date:
April 29, 2008 10:38
Subject:
prototypes, parsing and optrees
Message ID:
20080429173722.GW84051@plum.flirble.org
I'm confused. I thought that these two should be the same:

$ perl -MO=Concise -e 'sub foo (\@); foo @ARGV'
a  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 1 -e:1) v ->3
9     <1> entersub[t2] vKS/TARG,1 ->a
-        <1> ex-list K ->9
3           <0> pushmark s ->4
7           <1> refgen KM/1 ->8
-              <1> ex-list lKRM ->7
4                 <0> pushmark sRM ->5
6                 <1> rv2av[t1] lKRM/1 ->7
5                    <$> gv(*ARGV) s ->6
-           <1> ex-rv2cv sK/129 ->-
8              <$> gv(*foo) s ->9
-e syntax OK
$ perl -MO=Concise -e 'sub foo; foo \@ARGV'
a  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 1 -e:1) v ->3
9     <1> entersub[t2] vKS/TARG,1 ->a
-        <1> ex-list K ->9
3           <0> pushmark s ->4
7           <1> refgen lKM/1 ->8
-              <1> ex-list lKRM ->7
4                 <0> pushmark sRM ->5
6                 <1> rv2av[t1] lKRM/1 ->7
5                    <$> gv(*ARGV) s ->6
-           <1> ex-rv2cv sK/129 ->-
8              <$> gv(*foo) s ->9
-e syntax OK

But they're not:

$ diff -u <(perl -MO=Concise -e 'sub foo (\@); foo @ARGV') <(perl -MO=Concise -e 'sub foo; foo \@ARGV')
-e syntax OK
-e syntax OK
--- /dev/fd/63  2008-04-29 18:34:05.000000000 +0100
+++ /dev/fd/62  2008-04-29 18:34:05.000000000 +0100
@@ -4,7 +4,7 @@
 9     <1> entersub[t2] vKS/TARG,1 ->a
 -        <1> ex-list K ->9
 3           <0> pushmark s ->4
-7           <1> refgen KM/1 ->8
+7           <1> refgen lKM/1 ->8
 -              <1> ex-list lKRM ->7
 4                 <0> pushmark sRM ->5
 6                 <1> rv2av[t1] lKRM/1 ->7

The version without the prototype has an extra l flag on the refgen. (If I've
understood the documentation of B::Concise correctly, that means that it knows
that it's in list context).

How come the version with the \@ prototype isn't able to work out that it is
in list context?

(and am I right in thinking that prototypes only influence the parser - once
run time is reached, nothing is the wiser?)

Nicholas Clark

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About