Many people have pointed out the 'semicolon problem' with if and
else--that is, if Perl intuits a semicolon after every codeblock that
ends a blank line, you would have to cuddle all your elses:

        if $cond {
                ...
        }               <-- Virtual semicolon here
        else {
                ...
        }

My proposed solution to this is to make ALL codeblocks take an optional
'else', accessed by the $code.else attribute.  Depending on what sort of
builtin was being used, the else would mean different things:

        sub if($cond, &code) {
                $cond ?? code() :: &code.else();
        }
        
        sub while(&cond, &code) {
                if(cond()) {
                        #There's probably a way to do an
                        # else without a goto, but...
                TOP:
                        code();
                        return unless cond();
                        goto TOP;
                }
                else {
                        &code.else();
                }
        }
        
        sub for(@list is lazy, &code) {
                while(@list) {
                        &code(@list.unshift);
                }
                else {
                        &code.else();
                }
        }

The else on a subroutine declaration might be called if preconditions
(PRE and POST) didn't match, or it might just be ignored.

else would be able to take a single subroutine call instead of a block:

        if $cond {
                ...
        }
        else if $cond2 {
                ...
        }

Yes, I know this means that we have 'else if' instead of 'elsif', but
it's only two more characters and it makes the grammar cleaner.

--Brent Dax <[EMAIL PROTECTED]>
@roles=map {"Parrot $_"} qw(embedding regexen Configure)

>How do you "test" this 'God' to "prove" it is who it says it is?
"If you're God, you know exactly what it would take to convince me. Do
that."
    --Marc Fleury on alt.atheism

Reply via email to