in reply to Re^4: Why is const x const not a const?
in thread Why is const x const not a const?

It shows up as const AV in the opcode tree.

You can prove the list is flattened once using

for (1..2) { for ((), 4..8) { say $_++; } }

Update: Added missing parens.

Replies are listed 'Best First'.
Re^6: Why is const x const not a const?
by moritz (Cardinal) on Jan 23, 2012 at 19:11 UTC

      I don't know why B::Concise doesn't dump the contents of array, but B::Concise does show that the array is in the optree.

      $ perl -MO=Concise,-exec -e'my @a = 1..1000' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <0> pushmark s 4 <$> const[AV ] s ^ | 5 <1> rv2av lKP/1 6 <0> pushmark s 7 <0> padav[@a:1,2] lRM*/LVINTRO 8 <2> aassign[t4] vKS/COMMON 9 <@> leave[1 ref] vKP/REFC -e syntax OK

        I know that the array is there, but that doesn't convince me that those 100k scalars are built at compile time. There might just as well be a magic initializer attached to it that generates them at runtime, or at closure cloning time or whenever.

        No matter how big I chose the number in the range, I can't see increased memory consumption at compile time, which is why i suspect they aren't created at compile time.

Re^6: Why is const x const not a const?
by BrowserUk (Patriarch) on Jan 23, 2012 at 18:43 UTC
    It shows up as const AV in the opcode tree.

    You can prove the list is flattened once using

    I see the 1 & 2, and 4 & 8 as consts, but I'm also seeing what look to me like two loops. Perhaps you can interpret it better?:

    c:\test>perl -MO=Concise for (1..2) { for (4..8) { say $_++; } } ^Z t <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 4 -:1) v:{ ->3 s <2> leaveloop vK/2 ->t 7 <{> enteriter(next->p last->s redo->8) lKS/8 ->q - <0> ex-pushmark s ->3 - <1> ex-list lK ->6 3 <0> pushmark s ->4 4 <$> const[IV 1] s ->5 5 <$> const[IV 2] s ->6 6 <#> gv[*_] s ->7 - <1> null vK/1 ->s r <|> and(other->8) vK/1 ->s q <0> iter s ->r - <@> lineseq vKP ->- 8 <;> nextstate(main 2 -:2) v:{ ->9 o <2> leaveloop vK/2 ->p d <{> enteriter(next->l last->o redo->e) lKS/8 ->m - <0> ex-pushmark s ->9 - <1> ex-list lK ->c 9 <0> pushmark s ->a a <$> const[IV 4] s ->b b <$> const[IV 8] s ->c c <#> gv[*_] s ->d - <1> null vK/1 ->o n <|> and(other->e) vK/1 ->o m <0> iter s ->n - <@> lineseq vKP ->- e <;> nextstate(main 1 -:3) v:{ ->f k <1> preinc[t7] vK/1 ->l j <1> entersub[t6] sKRMS/NO(),TARG ->k f <0> pushmark s ->g - <1> ex-rv2sv sKM/1 ->h g <#> gvsv[*_] s ->h h <$> method_named[PV "say"] s ->i i <1> rv2cv /NO() ->j l <0> unstack v ->m p <0> unstack v ->q - syntax OK

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      Sorry, there was a set of parens missing. (Fixed.) I was about to reply to your post that for (CONST..CONST) is a counting loop rather than a loop iterating over the result of a range operator. There is no range operator, so the range operator cannot be flattened. Try

      perl -e"<>; exit; @a = 1..100000;" perl -e"<>; exit; for ((), 1..100000) {}"

      Results:

      perl -e"<>; exit; for ((),1.. 1000) {} 1,252K perl -e"<>; exit; for ((),1.. 10000) {} 1,784K perl -e"<>; exit; for ((),1.. 100000) {} 6,028K perl -e"<>; exit; for ((),1..1000000) {} 45,212K

      Update: Added results.

        You are forcing the issue there with the otherwise pointless parens.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?