logoalt Hacker News

201984today at 1:26 AM1 replyview on HN

Lua basically already has ternary operators anyway since "and" and "or" short circuit. I also don't see the need of adding additional syntax for it.

  local x = condition ? value_a : value b
  local x = condition and value_a or value_b

Replies

matheusmoreiratoday at 1:29 AM

> The classic Lua idiom a and b or c has a pitfall when b is nil or false: then c is returned, even when a is truthy.

> E.g. true and false or 42 returns 42, whereas true ? false : 42 returns the (expected) false.