Primitive type auto-imported

bool

type bool
Source: compiler/src/builtin_docs/types.hy

A boolean: true or false.

Conditions in if and while take a bool. && and || short-circuit; ! negates (it also accepts an int, where 0 is false). Booleans support == and != but are not ordered.

Casts with as: bool as int is 1 or 0; int as bool is true for any non-zero value.

Examples#

use tests::assert;
let ready = 3 > 2 && !false;
assert!(ready);
assert!(true as int == 1);
assert!(!(0 as bool));
assert!(show(ready) == "true");

See also#

  • int
  • float: A 64-bit IEEE-754 floating-point number.
  • byte: An unsigned 8-bit integer in 0..=255.
  • string: A UTF-8 text string.
  • unit: The type with a single value, (), used where there is no meaningful value.
↑ ↓ navigate ↵ open