| 1 | (* and and or evaluate their right side only when needed, also when |
| 2 | the left side is a constant: false and f(), true or f() call no f, |
| 3 | as a value and as a condition, under not too. *) |
| 4 | module ShortConst; |
| 5 | import Out; |
| 6 | |
| 7 | (* Says c, so the output shows each call *) |
| 8 | proc f(c: U8): BOOL; |
| 9 | begin |
| 10 | Out.char(c); |
| 11 | return true; |
| 12 | end; |
| 13 | |
| 14 | proc main*; |
| 15 | var b: BOOL; |
| 16 | begin |
| 17 | b := false and f('a'); |
| 18 | b := true or f('b'); |
| 19 | b := not (false and f('c')); |
| 20 | if b then Out.char('1'); end; |
| 21 | if not (true or f('d')) then Out.char('x'); end; |
| 22 | b := false and f('e') and f('f'); |
| 23 | b := true and f('g'); |
| 24 | b := false or f('h'); |
| 25 | if false and true then Out.char('x'); end; |
| 26 | Out.char(10); |
| 27 | end; |
| 28 | |
| 29 | end ShortConst. |