Remix.run Logo
demilicious 2 hours ago

That’s why “if” should just be an expression

NuclearPM 10 minutes ago | parent | next [-]

Yep. Everything should be.

matheusmoreira 2 hours ago | parent | prev [-]

This is the best answer in my opinion. Ternary is just sugar for an expressive if. LuaJIT seems to be focusing on adding new syntax though, maintainer might not be amenable to updating existing semantics.

wavemode an hour ago | parent [-]

I don't think if-expressions have to affect existing semantics. Basically, in the parser you would have two different kinds of AST nodes, one for when the `if` keyword is encountered in statement position and another for when it's encountered in expression position.

Right now, `if` in expression position is just a syntax error ("unexpected symbol")