Skip to main content

Optional Chaining and the Try operator

I want to have them all: optional-chaining, unwrap and try operators. Rust includes the try operator ? which is transformed into construction with return on the "fail" case, though it is possible to use and_then as an alternative to JS/C# ?. operator (optional chaining). The other thing is that Jacy does not have the same syntax for macros as Rust because ! is reserved as postfix "unwrap" operator, thus expression like foo!(...) is std::ops::Unwrap(foo)(...) but not foo!(...) macro call. By the way, it is possible to both use macros syntax with ! and have ! as postfix operator -- store macros in the values namespace (i.e. name foo! will collide with e.g. function foo), but I don't like this solution.

The other problem is that if we have ? as optional chaining, how do we use the "try" operator? (? in Rust).

Initials

I'd like to describe all the possible operators/ways to implement I see.

OperatorPossible usage
? operatorOptional chaining / Try operator
?. distinct operator (. is included in ?.)
! operator
&. operator from Ruby (optional chaining, aka safe navigation)
??I want to use it for