Would it make sense to have the failure bound to the function parameter
rather than the subset? eg.:
sub foo (Str $name where { $_ ~~ :f } else { die "Houston, we don't have a
file" } ) { ... }
Just a thought...
On Tue, Jan 5, 2010 at 1:07 AM, Ovid
<[email protected]>wrote:
> --- On Mon, 4/1/10, yary <[email protected]> wrote:
>
> > From: yary <[email protected]>
>
> > How about
> > multi sub foo(Any $name) { die "Houston, we have a major
> > malfunction."}
>
> Looks like tha would work, but it forces the developer to remember to write
> this extra code every time they may have a constraint failure, if they
> forget, we're back to the old, cryptic message. It would be much nicer to
> be able to do this (psuedo-code, obviouly):
>
> subset Filename of Str where { $_ ~~ :f }
> :OnFail { "No such file: '$_'" }
> subset Celsius of Num where { $_ >= -273.15 }
> :OnFail { "Celsius temperature should be a Num >= -273.15, not '$_' " }
>
> With something akin to that, developers won't have to write extra
> boilerplate every time a constraint fails. Plus, the code is friendlier :)
>
> Cheers,
> Ovid
> --
> Buy the book - http://www.oreilly.com/catalog/perlhks/
> Tech blog - http://use.perl.org/~Ovid/journal/
> Twitter - http://twitter.com/OvidPerl
> Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
>
>
>
--
John "ash" Harrison