Re: Catching exceptions in expressions

2018-08-03 Thread Patrick R. Michaud
Yes; but then I think that something like infix: probably just ends up as a macro somehow. I just didn't know the state of macros in Perl 6 well enough to be able to head down that route. :) Pm On Fri, Aug 03, 2018 at 10:32:41PM +0200, Elizabeth Mattijsen wrote: > Sometimes I wish we could

Re: Catching exceptions in expressions

2018-08-03 Thread Elizabeth Mattijsen
Sometimes I wish we could use Thunk as a type: sub infix:(Thunk:D $block, $otherwise) { } which would then allow you to do: my $sixdivzero = divide(6,0) rescue -1; # note absence of curlies One can wish, can’t one? Liz > On 3 Aug 2018, at 22:18, Patrick R. Michaud wrote: > > Maybe

Re: Catching exceptions in expressions

2018-08-03 Thread Patrick R. Michaud
Maybe something like...? $ cat t.p6 sub infix:(Callable $block, $otherwise) { CATCH { return $otherwise; } $block(); } sub divide($a, $b) { die "Zero denominator" if $b == 0; $a / $b } my $sixdivzero = { divide(6,0) } rescue -1; say "6/0 = ", $sixdivzero; my $sixdivtwo = { divide(6,2)

Re: Catching exceptions in expressions

2018-08-03 Thread Simon Proctor
Hi Sean. I hope my second answer in stackoverflow gets closer to what you want. I am still trying to think of a more idiomatic way of handling to situation. On Fri, 3 Aug 2018, 19:29 Sean McAfee, wrote: > I posted about this subject on Stack Overflow yesterday[1], but I chose a > poor

Catching exceptions in expressions

2018-08-03 Thread Sean McAfee
I posted about this subject on Stack Overflow yesterday[1], but I chose a poor example of something that raises an exception (dividing by zero, which apparently doesn't necessarily do so) on which the answers have mostly focused. I was looking for a way to evaluate an expression, and if the