language · language ·

Boolean logic and short-circuiting

Use !, and, and or with bool values. and and or short-circuit, so the right side runs only when needed.

!andcomplete-programcpufalselanguagelogicortrueyeho

Put cheap or safety-critical guards first so later expressions run only inside their valid domain.

!condition
left and right
left or right

Status: stable

Short circuit

Put cheap or safety-critical guards first so later expressions run only inside their valid domain.

cpu · complete-program · type checked

list of int empty = []
bool andResult = false and empty[0] == 1
bool orResult = true or empty[0] == 1

if !andResult and orResult
{
    Console.Log("short-circuit-ok")
}
else
{
    Console.Log("short-circuit-bad")
}
project.mech
package = "tests.compiler.fastContract.shortCircuit"
Notes and source

The canonical unary spelling is !, not the editor grammar's historical not token.

There are no truthy or falsy conversions.

yeho/parser_expressions.cpp parseOr/parseAnd/parseUnary; conformance control.boolean-conditions