Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^8: Short-circuiting a map list. (This works! But ...)

by ikegami (Pope)
on Oct 09, 2011 at 19:18 UTC ( #930486=note: print w/ replies, xml ) Need Help??


in reply to Re^7: Short-circuiting a map list. (This works! But ...)
in thread Short-circuiting a map list.

No. You've already shown it doesn't do that in practice (in Re^3: Short-circuiting a map list. (This works! But ...)), and it doesn't do that according to the documentation.

A BLOCK by itself (labeled or not) is semantically equivalent to a loop that executes once.

If the last statement is a loop control structure like a foreach or a while, the returned value is unspecified.

You just got lucky here.


Comment on Re^8: Short-circuiting a map list. (This works! But ...)
Select or Download Code
Re^9: Short-circuiting a map list. (This works! But ...)
by BrowserUk (Pope) on Oct 09, 2011 at 19:27 UTC

    Your conclusion, based on those two quotes, is a non sequitur.

    1. "semantically equivalent" is not the same as "is".
    2. As already pointed out, the bare block is not "the last statement [in the subroutine]".

    2 + 2 != 22.


    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.

      You can argue all you want, but it's not going to change the fact that the return value of loops (including the bare loop) is not defined. They can and do produce junk in some circumstances. There was talk of making loops act like map wrt to their return value, but it hasn't been done.

        Geez! How many hints do you need?

        The "If the last statement is a loop control structure..." restriction comes from here:

        • Like many languages, Perl provides for user-defined subroutines.
        • These may be located anywhere in the main program.
        • Loaded in from other files via the do, require, or use keywords.
        • Any arguments passed in show up in the array @_.
        • A return statement may be used to exit a subroutine.
        • If no return is found and if the last statement is an expression, its value is returned.
        • If the last statement is a loop control structure like a foreach or a while , the returned value is unspecified.
        • Subroutines can return Scalar, Array or Hash.

        It is only applied to the "last statement of a subroutine". Not to the last statement of a do block?

        For counterpoint, not a millions lines away from where that quote comes from, there is another, rather more applicable quote:

        The return value of any block, including those used in subroutines, is taken as the value of the last evaluated expression.

        And I'm pretty damn confident that I could find numerous examples of you using, and recommending the use, of the return value from a block.

        Does this look familiar:

        eval { ...; 1; } or ...;

        But suddenly, you read a bit of the documentation, apply it to the wrong circumstance, assume that your misinterpretation is the only interpretation.

        I seem to recall that someone fairly authoritative suggested that when the documentation is inadequate or in conflict -- as with those two quotes -- the reference specification is the implementation.

        So, jump up and down all you like, you're still drawing the wrong conclusion, and I'm bored with watching you do so. So just stop.


        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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2014-07-24 07:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (158 votes), past polls