differential-datalog icon indicating copy to clipboard operation
differential-datalog copied to clipboard

"if let" for DDlog

Open blp opened this issue 5 years ago • 1 comments

Rust has a syntactic construct "if let": https://doc.rust-lang.org/stable/rust-by-example/flow_control/if_let.html. This would be useful in DDlog as well. It would simplify commonly found patterns in OVN like this:

        match (set_nth(acl.name, 0)) {
            None -> (),
            Some{name} -> vec_push(strs, "name=\"${name}\"")
        };

to something more like this:

if (Some{var name} = set_nth(acl.name, 0)) {
    vec_push(strs, "name=\"${name\"")
}

Currently the latter produces an error message like this:

ddlog: error: ../northd/ovn_northd.dl:1647:6-1647:21: Type constructor in the left-hand side of an assignment is only allowed for types with one constructor,  but "std.Option" has multiple constructors

blp avatar Apr 04 '20 19:04 blp

Agreed, this is often much more ergonomic than match. We should support the if-else form as well.

ryzhyk avatar Apr 04 '20 21:04 ryzhyk