[Pdx-pm] the quest for return_if

benh ben.hengst at gmail.com
Wed Jun 27 07:59:27 PDT 2007


austin that looks perfect. now off to work and see how well my day
goes because of it. I never really though about useing the testing
suit.

On 6/26/07, Austin Schutz <tex at off.org> wrote:
> On Tue, Jun 26, 2007 at 05:57:19PM -0700, Eric Wilhelm wrote:
> > # from benh
> > # on Tuesday 26 June 2007 05:17 pm:
> >
> > >Ideally I would love to do this:
> > >
> > >sub return_if {
> > >   my ($eval, $value) = @_;
> > >   $value = $eval if !defined($value);
> > >   {FROM_THE_POINT_WHERE_I_WAS_CALLED}->return $value if
> > > defined($eval); }
> >
> > That's not exactly clear.  Are you trying to return the value if it is
> > defined?  That is, you're trying to get away from two-line things like:
> >
> >   my $val = answer($param);
> >   return($val) if(defined($val));
> >
> > ?
> >
> > Yeah, that could be tighter, but I don't recall ever being bothered by
> > it (then again, I'm not looking at ten pages of them, are you?)
> >
> > The opposite is pretty concise:
> >
> >   return() unless(defined(my $val = answer($param)));
> >
>
>         I believe the intent is to do something like
>
> assert( test() );
>
>         and be able to have the return portion automatic. If you understand
> what is meant it is far more concise. But the language doesn't cleanly
> support it- which may be a boon, since it would be surprising behavior.  I had
> at one point had the same wish, but something that fundamental to the
> operation of the interpreter would be very hard to bolt on cleanly. Well,
> unless you are a lot more clever than I am.
>
>         If true/false will work for you, you can distill it to a simple test
> case:
>
>         assert( test() ) or return;
>
>         If testing defined():
>
>         defined(assert(test())) or return;
>
>
>         Basically all variations on the theme of Eric's response.
>
>
>         Austin
> _______________________________________________
> Pdx-pm-list mailing list
> Pdx-pm-list at pm.org
> http://mail.pm.org/mailman/listinfo/pdx-pm-list
>


-- 
benh~


More information about the Pdx-pm-list mailing list