M2
M2 copied to clipboard
try..then without else clause
Currently this doesn't work:
i1 : try true then 2
stdio:1:1:(3): error: syntax error : expected 'else' to match this 'try'
I would have expected it to be treated like this:
i2 : try true then 2 else null
o2 = 2
i3 : try error() then 2 else null
i4 :
Similar to how if..then..else works:
i1 : if true then 2
o1 = 2
i2 : if true then 2 else null
o2 = 2
i3 : if false then 2 else null
i4 :
Such syntax is not needed, for one can simply write try ( foo ; 2 ) else null. Then if no error occurs in foo, the value will be 2.
The syntax is cleaner without parentheses, so what's the harm?
Well, if the then clause is not mandatory, there's no harm, but where's the gain that corresponds to all that work? Usually, one wants the value of foo, unless some error occurs, so one writes something like try foo else 3331333.