spider
spider copied to clipboard
Conditional Expression without else
var v = x if a;
compiles to:
var v = x if a else null;
which compiles to:
var v = a ? x : null;
will this work?
(x if a) == 5
@Namek yes
+1. Will it still work if if <expr> then <expr> else <expr>
#98 is to be added?
I have rarely ever though I would want something like this, ternary expressions never felt wrong. But when I have more than one condition the ternary mode can become a mess. This is not the best example in the world but it illustrates my point.
var size = useLarge ? "large" : useSmall ? "small" : "medium";
rewritten with the proposed form
var size = "large" if useLarge else "small" if useSmall else "medium";
formats nicely too
var size = "large" if useLarge else
"small" if useSmall else
"medium";
@andrewluetgers :heart:
+1