Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^3: return if 0

by zigdon (Deacon)
on Jun 22, 2009 at 23:16 UTC ( #773788=note: print w/replies, xml ) Need Help??

in reply to Re^2: return if 0
in thread return if 0

To be fair, it wouldn't be insane for the compiler to know that the block can never execute, and just remove it completely.

Except for the part that it has unexpected consequences, as we've been discussing.

-- zigdon

Replies are listed 'Best First'.
Re^4: return if 0
by ikegami (Pope) on Jun 23, 2009 at 01:02 UTC
    It does remove the if, but it keeps the constant to maintain the behaviour.
    >perl -MO=Concise,-exec,f -e"sub f { return 1 if 0 }" main::f: 1 <;> nextstate(main 1 -e:1) v 2 <$> const[IV 0] s/SHORT 3 <1> leavesub[1 ref] K/REFC,1 -e syntax OK

    Compared to:

    >perl -MO=Concise,-exec,f -e"sub f { return 1 if $c }" main::f: 1 <;> nextstate(main 1 -e:1) v 2 <#> gvsv[*c] s 3 <|> and(other->4) K/1 4 <0> pushmark s 5 <$> const[IV 1] s 6 <@> return K 7 <1> leavesub[1 ref] K/REFC,1 -e syntax OK

    Note the and operator (used to implement if) is missing from the first snippet.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://773788]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2019-05-26 01:33 GMT
Find Nodes?
    Voting Booth?
    Do you enjoy 3D movies?

    Results (152 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!