Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: return if 0

by zigdon (Deacon)
on Jun 22, 2009 at 23:16 UTC ( [id://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 (Patriarch) 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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-26 04:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found