in reply to Perl 6 will make amends (was:Perl's Bad Ideas)
in thread Perl's Bad Ideas

Seeing everything is a closure, is the statement part of a conditional in the same block as the body itself?
# For example while (my $el = pop @els){ # Body of loop } # Is it equivelant to this? { my $el = pop @els; { # Body of loop } } # Or this? { my $el = pop @els; # Body of loop }


-Lee

"To be civilized is to deny one's nature."

Replies are listed 'Best First'.
Re: Re: Perl 6 will make amends (was:Perl's Bad Ideas)
by TheDamian (Vicar) on Apr 07, 2002 at 21:24 UTC
    ...is the statement part of a conditional in the same block as the body itself?

    No, the conditional is outside the block, both physically and logically (err...physiologically? ;-).

    Your example is equivalent to:

    my $el; while ($el = pop @els) { # Body of loop }

    BTW, in Perl 6, if and while (and the rest of the control structures) can be thought of as built-in functions. As if they were:

    sub while (BOOL $condition, &closure) {...} sub if (BOOL $condition, &closure) {...}

    That's why the conditional is not part of the block: it's an entirely separate argument to the control structure.

    And, yes, you'll be able to get the signature (a.k.a. prototype) of a control structure, and overload it, and redefine it (lexically).

    And you'll probably be able to write bad things like:

    if condition(), &call_me;

    and worse things like:

    &debug := { if BEGIN{$debug}, &^action }; # and later... debug { print "here" }
      Thanks for the enlightenment. Do you think there will be a mechanism to detect this? One thing I think would be nice would be able to tell if you are called in a control structure or not for lazy DWIM functions, like this findone { coderef } @array

      -Lee

      "To be civilized is to deny one's nature."
        Thanks for the enlightenment.
        Satori can arrive in the most unlikely ways. But I suspect I really only brought you information. ;-)
        ...nice would be able to tell if you are called in a control structure or not for lazy DWIM functions
        Sure. Depending on what kind of context information you're after, you'll use either caller or want (the successor to wantarray).