develooper Front page | perl.perl5.porters | Postings from July 2009

Re: Rvalue given() blocks

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
July 20, 2009 02:34
Subject:
Re: Rvalue given() blocks
Message ID:
b77c1dce0907200234x6f5e4b6dod33813fc1e140910@mail.gmail.com
2009/7/20 Vincent Pit <perl@profvince.com>:
> Just as the title says, this patch makes given() blocks return values,
> with the following rules :
> - if an explicit break is encountered, return an empty list ;
> - if a when/default clause is true (and doesn't contain an explicit
> break), return the value of the last evaluated expression of the block ;
> - if all conditions were false, return the value of the last evaluated
> expression of the block.
> I've also made when/default not return anything (unlike 'if' and
> 'unless' which returns the value of the condition).
>
> Regarding the implementation, I added 'switch' to the 'term' rule. This
> made the YYLAST value increase a lot :
>
> -#define YYLAST   2061
> +#define YYLAST   2446
>
> I'm not a bison specialist, so I'd like to know if there isn't some kind
> of heavy penalty hidden there.
>
> Then I made scalar()/list() correctly propagate into given/when OPs.
> There's very little run-time changes. pp_leavegiven() was just taught to
> correctly set the stack pointer. It also mimics pp_leavetry() to make
> sure that all the stack elements are correctly tainted/mortalized.

This is extremely neat.
However by looking at the perly.y part of the patch (I haven't looked
at the other ones yet) I see that you add switch as a derivation for
the term rule, but switch can begin with a label. And terms don't.

I'd rather have a new rule
switch : label given;
and add given to term.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About