Tech News
← Back to articles

Imagining a language without booleans

read original related products more articles

Imagining a Language without Booleans

Let’s start where I started. Just thinking about if statements.

An if with an else can produce a value:

// C int x = - 5 ; int abs_x = x > 0 ? x : - x ;

# Python x = - 5 abs_x = x if x > 0 else - x

// Rust let x = - 5 ; let abs_x = if x > 0 { x } else { - x };

What about an if without an else ?

// C int x = - 5 ; int abs_x = x > 0 ? x ; // Syntax error!

# Python x = - 5 abs_x = x if x > 0 # Syntax error!

// Rust let x = - 5 ; let abs_x = if x > 0 { x }; // Type error -- evaluates to ()!

... continue reading