inkle / ink

inkle's open source scripting language for writing interactive narrative.
http://www.inklestudios.com/ink
MIT License
4.07k stars 489 forks source link

Short-circuit Logical AND expressions #816

Open russellquinn opened 1 year ago

russellquinn commented 1 year ago

I have an Ink function of the form:

=== function can_do_something()
    ~ return some_var == 0 && some_expensive_to_run_external_function() == true

some_expensive_to_run_external_function gets called every time, even when some_var == 0

Ideally, for performance, Ink would follow other languages where typical behavior is:

&& guarantees left-to-right evaluation: the second operand is not evaluated if the first operand is false.

joningold commented 1 year ago

Agreed, this would be better. For now, you can optimise by nesting: { conditionA: { expensive_conditionB: stuff } } and help the ink along that way

russellquinn commented 1 year ago

Right, that would force the desired behviour. Thanks!