▲ 84 ▼ ternary opruleator (lemmy.blahaj.zone) submitted 11 months ago by guber@lemmy.blahaj.zone to c/onehundredninetysix@lemmy.blahaj.zone 19 comments fedilink hide all child comments cross-posted from: https://lemmy.blahaj.zone/post/31679150 proportional reaction
[–] MistressRemilia@lemmy.sdf.org 5 points 11 months ago (2 children) # I mean, Crystal does have a ternary operator, too... bar = case something in "aaa" then true in "bbb" then false end foo = if bar 69 else 42 end ;; Or CASE or IF or COND or whatever (let* ((bar (ecase (something) (:aaa t) (:bbb nil))) (foo (if bar 69 42))) ) permalink fedilink source hideshow 4 child comments replies: [–] ricecake@sh.itjust.works 8 points 11 months ago Yeah, the problem isn't "conditional expressions", it's "terse syntax", and operator rules that you need to just memorize because they're special and different. Also being limited such that you need to nest the extremely deeply if you, for whatever, you need to have a complex inline condition. I like the case expression , although I mostly know it from erlang. permalink fedilink source parent [–] Sv443@sh.itjust.works 6 points 11 months ago* (1 child) I've been called slurs before for using immediately invoked anonymous function expressions with switch cases in JS const [val1, val2] = (() => { switch(whatever) { case "foo": return [1, 2]; case "bar": return [3, 4]; default: return [0, 0]; } }))(); permalink fedilink source parent hideshow 2 child comments replies: [–] gandalf_der_12te@lemmy.blahaj.zone 3 points 11 months ago (1 child) const [val1, val2] = ({ "foo": [1, 2], "bar": [3, 4], })[whatever] || [0, 0]; permalink fedilink source parent hideshow 2 child comments replies: [–] Sv443@sh.itjust.works 2 points 11 months ago 🤫 permalink fedilink source parent
[–] ricecake@sh.itjust.works 8 points 11 months ago Yeah, the problem isn't "conditional expressions", it's "terse syntax", and operator rules that you need to just memorize because they're special and different. Also being limited such that you need to nest the extremely deeply if you, for whatever, you need to have a complex inline condition. I like the case expression , although I mostly know it from erlang. permalink fedilink source parent
[–] Sv443@sh.itjust.works 6 points 11 months ago* (1 child) I've been called slurs before for using immediately invoked anonymous function expressions with switch cases in JS const [val1, val2] = (() => { switch(whatever) { case "foo": return [1, 2]; case "bar": return [3, 4]; default: return [0, 0]; } }))(); permalink fedilink source parent hideshow 2 child comments replies: [–] gandalf_der_12te@lemmy.blahaj.zone 3 points 11 months ago (1 child) const [val1, val2] = ({ "foo": [1, 2], "bar": [3, 4], })[whatever] || [0, 0]; permalink fedilink source parent hideshow 2 child comments replies: [–] Sv443@sh.itjust.works 2 points 11 months ago 🤫 permalink fedilink source parent
[–] gandalf_der_12te@lemmy.blahaj.zone 3 points 11 months ago (1 child) const [val1, val2] = ({ "foo": [1, 2], "bar": [3, 4], })[whatever] || [0, 0]; permalink fedilink source parent hideshow 2 child comments replies: [–] Sv443@sh.itjust.works 2 points 11 months ago 🤫 permalink fedilink source parent