DriftScript
Documentation

Guide

Expressions and statements

Precedence, and the two things the language will not guess: truthiness and widening.

Precedence holds no surprises. What is worth learning here is the two places the language refuses to guess, because both are places most languages guess and both are where a value quietly becomes something else.

There is no truthiness

A condition must be bool. A count is not a condition, an empty string is not a condition, and a handle is not a condition. The error says to compare explicitly, because the fix is to write down which comparison you meant and the compiler cannot know that.

// Deliberately refused.
//
// There is no truthiness. A condition must be `bool`, and the fix is to say what you meant:
// `if count != 0`.

fn ready(count: u32) -> bool {
    if count {
        return true
    } else {
        return false
    }
}

There is no implicit widening

Adding a u8 to a u32 names the conversions available and picks none of them. A language that guessed would be making that decision in a place nobody reads, on a line that looks like arithmetic.

// Deliberately refused.
//
// There is no implicit widening. The compiler names the conversions rather than guessing which
// one was meant, because the guess is where a value quietly changes width.

fn add(a: u8, b: u32) -> u8 {
    return a + b
}

Declaration order carries no meaning

Functions may be called before they are declared. A file is a set of declarations rather than a sequence of them, so moving one does not change what the file means.