Yaakov Belch perl6-at-yaakovnet.net |Perl 6| wrote:
Let me explain why this is useful and why I think this is "the right thing":
First of all, it provides a very light-weight exception handling using
well-known ideoms like:
  $file_content=read_file($filename) // $default_value;
  compute_statistics($data) // write_log_message("stats failed: $!");

With the proposed change, these ideoms work whether the functions throw
exceptions or not.

You can change the meaning of "fail" to throw exceptions or to return the unthrown object which is an interesting value of undef. So under
   use fail 'return';
your line works as intended. This is what you should do if you are expecting failure in this case.

A macro can give you some syntactic sugar for that:

   macro ttt ($x) is parsed<expression>
   {
    return "{ use fail 'return'; $x; }";
   }



Reply via email to