quantified-uncertainty / squiggle

An estimation language
https://squiggle-language.com
MIT License
150 stars 23 forks source link

Reducer: and, or, xor operators( && || ^ ) should use lazy evaluation #559

Open umuro opened 2 years ago

umuro commented 2 years ago

In the current implementation logical operators are not lazy. However, all logical operators need to evaluate their second argument based on the value of their first argument. Example false && truth(b) should not execute truth(b)at all.

umuro commented 2 years ago

@berekuk This issue can be fixed at the parser level

berekuk commented 2 years ago

How? I know you could rewrite these as ternaries, but that would conflict with plans from #1107.

Maybe it makes sense to do the rewrite as ternaries on peggyNode -> expression step, though. Or we could just add these as expression variants, I don't really mind having one or two more branches in Reducer_Expression.evaluate.

umuro commented 2 years ago

Creating Peggy nodes for them, then converting to ternary expressions. As you say. Adding such simple cases as expression variants is not necessary. Keeps the interpreter clean

On Tue, Oct 4, 2022, 17:40 Vyacheslav Matyukhin @.***> wrote:

How? I know you could rewrite these as ternaries, but that would conflict with plans from #1107 https://github.com/quantified-uncertainty/squiggle/issues/1107.

Maybe it makes sense to do the rewrite as ternaries on peggyNode -> expression step, though. Or we could just add these as expression variants, I don't really mind having one or two more branches in Reducer_Expression.evaluate.

— Reply to this email directly, view it on GitHub https://github.com/quantified-uncertainty/squiggle/issues/559#issuecomment-1267199725, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAALOF6OJRMGYCF2WRLWSWLWBRFWBANCNFSM5WPTZ3OA . You are receiving this because you were assigned.Message ID: @.***>