On 12/07/2013 02:14 AM, Jordi Boggiano wrote:
On Sat, Dec 7, 2013 at 2:07 AM, spir <denis.s...@gmail.com> wrote:
Maybe it's only me, but this not at at all clear to my eyes. My imagined
soluton (for a totally different lang) was something like this, on the
caller side:

         ucodes = s.utf8_decode()!       // source should be correct, error
on failure
         ucodes = s.utf8_decode()?       // logical failure expected, return
None or whatnot

(But maybe _this_ is obscure to your eyes?)

Looks like our mails had a race condition on this one, but
highlighting the cases where we expect a perfect world (i.e. !) is
probably better.

However, if you just call the method without anything it would be the
same as calling it with ? suffix as far as I understand, so I'm not
sure what the point is of keeping that one.

This is because you think in terms of Option, taking it for granted as if it were natural (thinking); "call the method without anything" here returns an Option element, thus (for you) the case '?' is doing nothing (more). In fact, from the point of view of a caller wanting an actual result, barely, the '?' case wraps it into an Option "box", while the '!' is the one doing nothing... Clear?

Another way of doing that is having a transparent 'none' flag (or more generally 'failure' or 'naomaly') somewhere. In '!' case, an eventual anomaly during func exec causes the program to stop on error. In '?' case, it sets this flag, which then to be tested by the caller. The signs '!' '?' thus parameterise the behaviour of (possibly failing) called funcs in anomalous cases.

There is an implementation of light exception handling for C (in ASM in fact) that sets the carry flag that way (carry, because it is meaningless in-between funcs, and is the only CPU flag set-able at will).

Denis
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to