Support for statements in expr? #566
-
Hi,
I know for a fact that with enough perseverance even the most complicated conditions & return values can be represented as [extremely] nested ternary expressions and fed to the expr VM. But those are not maintenance friendly and are hard to debug & test during development. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Yes! This is one of the things I'm definitely looking to add into expr. I discussed this topic with several big companies which have huge expr expressions. I'm thinking to add support for if expressions and return statement. First thing is to add alternative for ternary operator
I'd like to keep syntax for if close to go, but if should still be an expression. let var = if cond > 0 {
"success"
} else {
"also success"
} With if as expression, if cond > 0 {
return "success"
}
foo + bar |
Beta Was this translation helpful? Give feedback.
-
Hey @antonmedv, Thanks for replying!
Basically, we need not return from the |
Beta Was this translation helpful? Give feedback.
Yes, this is something that we can also add the the language. Also assignment operator will be needed. And we need to decide if only vars can be assigned or env values as well.