Boolean, Char, and Byte
Cloth provides four small named types for logical values, character data, and byte-level work: bool, char, byte, and bit.
bool
bool represents a logical value. It has exactly two values, denoted by the literals true and false.
let active = true;
let done = false;bool is the type produced by every comparison operator (==, !=, <, <=, >, >=) and by the type-check (is) and membership-check (in) operators. It is the required type of the condition expression in if, while, do-while, and the C-style for.
The logical operators and and or operate on bool operands and produce a bool result. The unary operator ! negates a bool.
The standard library provides a println overload for bool that prints the literal text true or false:
import cloth.io.Out::{ println };
println(true); // prints: true
println(false); // prints: falsechar
char represents a single character. It is a fixed-size value type and may be passed, stored, and compared like any other primitive.
char is distinct from string. A string is a sequence of characters; a char is a single character. Conversion between the two is explicit.
byte
byte represents an 8-bit value. It is the type used when working with raw memory, file contents, or other binary data where individual octets are the unit of meaning.
byte corresponds in size to u8. The two are distinct types in source — they differ in intent: u8 represents an unsigned integer in the range 0–255, while byte represents an opaque octet whose interpretation depends on the surrounding context.
bit
bit represents a single bit. It is the smallest addressable value in Cloth and is used in contexts where a single Boolean-like signal is more appropriate than a full bool — for example, when describing bitfields or hardware-level data layouts.
Summary
| Type | Width | Domain |
|---|---|---|
bool | 1 (logical) | true, false |
char | platform-defined character width | a single character |
byte | 8 bits | 0..=255, no interpretation |
bit | 1 bit | 0 or 1 |
These four types are reserved keywords and cannot be redefined.