Re: Rationale for $!

2016-01-28 Thread Moritz Lenz
Hi,

On 01/28/2016 04:06 PM, Todd C. Olson wrote:
> Is there a way to make the exception be thrown eagerly, at the devision 
> statement rather than waiting until use, at the say statement?

Yes, 'use fatal;'

Cheers,
Moritz


Re: Rationale for $!

2016-01-28 Thread Brandon Allbery
On Wed, Jan 27, 2016 at 11:00 AM, Felipe Gasper 
wrote:

> Unrelated, but, does open() not throw on failures anyway? (Noodling with
> the perl6 REPL just now seems inconclusive.)


There have been issues with failures in sink context not throwing, IIRC? So
how you were noodling can matter.


-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Re: Rationale for $!

2016-01-28 Thread Brandon Allbery
On Wed, Jan 27, 2016 at 11:06 AM, Felipe Gasper 
wrote:

> On 27 Jan 2016 11:03 AM, Brandon Allbery wrote:
>>
>> On Wed, Jan 27, 2016 at 11:00 AM, Felipe Gasper > > wrote:
>>
>> Unrelated, but, does open() not throw on failures anyway? (Noodling
>> with the perl6 REPL just now seems inconclusive.)
>>
>> There have been issues with failures in sink context not throwing, IIRC?
>> So how you were noodling can matter.
>>
>
> felipe@Macintosh-3 00:45:46 /
> > perl6
> > open("/dfgsgsdfgd", :r);
> Failed to open file /dfgsgsdfgd: no such file or directory
> > my $f = open("/dfgsgsdfgd", :r);
> Failed to open file /dfgsgsdfgd: no such file or directory
> > print $f;
> (HANDLED) Failed to open file /dfgsgsdfgd: no such file or directory
>   in any  at
> /Users/felipe/.rakudobrew/moar-2015.12/install/share/perl6/runtime/CORE.setting.moarvm
> line 1
>   in block  at  line 1
>

Looks to me like both of them threw? and $f is set to the Failure object
instead of a filehandle, which has an annotation saying that it was indeed
handled (thrown).

Perl 6 has two ways to indicate failure: you can throw immediately, or you
can return a Failure object which is a "lazy exception". The latter allows
a program to introspect the return value to recognize and handle a Failure
without actually throwing it (faster and often cleaner than catching it),
or if something just tries to use the value without checking then it throws
at that point. It remembers the context in which it was created, so the
traceback should indicate that it happened in the open call.

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Re: Rationale for $!

2016-01-28 Thread Todd C. Olson
Slight change in focus of question ...

> On We 2016-01-27, at 09:15, Felipe Gasper  wrote:
> ---
> use v6;
> 
> my $x = 10;
> my $y = 0;
> 
> my $z = $x / $y;
> 
> my $exception;
> {
>{
>say $z;
>CATCH {
>default {
>$exception = $_;
>}
>}
>}
> }
> 
> if ($exception) {
>say "There was an exception: $exception ($!)";
> }
> 
> say "still running";
> ---


Is there a way to make the exception be thrown eagerly, at the devision 
statement rather than waiting until use, at the say statement?

Regards,
Todd Olson