vmware / differential-datalog

DDlog is a programming language for incremental computation. It is well suited for writing programs that continuously update their output in response to input changes. A DDlog programmer does not write incremental algorithms; instead they specify the desired input-output mapping in a declarative manner.
MIT License
1.36k stars 117 forks source link

"if let" for DDlog #607

Open blp opened 4 years ago

blp commented 4 years ago

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
ryzhyk commented 4 years ago

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