Doesn't seem like enough bang for the buck to me.  In your first example you
save 3 vertical lines but get a really wide one in return, and lose
some indentation
levels but add more syntax and conceptual overhead to the language.

Might be my lack of imagination, but the feature doesn't seem to expand out
to many other use cases, either.

Your second case you could write as:

let foo = get_option("foo");
let bar = get_option("bar");
if foo.is_some() && bar.is_some() {
    use(foo.unwrap(), bar.unwrap());
}





On Monday, September 23, 2013, Oren Ben-Kiki wrote:

> A question / proposed syntax... How about allowing writing something like:
>
>     if (Some(foo), Some(bar)) ~~ (get_option("foo"), get_option("bar)) {
>         use(foo, bar);
>     }
>
> Instead of having to write the more combersome:
>
>     match (get_option("foo"), get_option("bar")) {
>         (Some(foo), Some(bar)) => {
>             use(foo, bar);
>         },
>         _otherwise => {},
>     }
>
> Not to mention:
>
>     let foo_bar: bool = (Some(_foo), Some(_bar)) ~~ (get_option("foo"),
> get_option("bar"));
>
>     match (get_option("foo"), get_option("bar")) {
>         (Some(foo), Some(bar)) => {
>             use(foo, bar);
>         },
>         _otherwise => {},
>     }
>
> Instead of the very cumbersome:
>
>     let foo_bar: bool =
>         match (get_option("foo"), get_option("bar")) {
>             (Some(_foo), Some(_bar)) => true,
>             _otherwise => false,
>         }
>     }
>
> So, in general allow `pattern ~~ expression` to be a boolean expression
> and if it is used in an "if" statement allow it to introduce the matched
> variables to the "then" scope.
>
> The operator doesn't have to be ~~, it could be anything unique (though
> using ~ for matching has a lot of precedence in other languages).
>
> Thoughts?
>
> Oren Ben-Kiki
>
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to