Browse the documentation

Preview documentation for AEL Beta 0.0.1 — launching soon

Types

AEL, the Agent Engineering Language, will be statically typed: every value will have one type, known when you check your code, and no value will change type on its own. Every collection will have a fixed capacity, written in its type, so a program's memory use will be predictable.

Status

Planned for AEL Beta 0.0.1. AEL is not available yet.

Integers

TypeRange
i8−128 to 127
i16−32,768 to 32,767
i32−2,147,483,648 to 2,147,483,647
i64−9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
u80 to 255
u160 to 65,535
u320 to 4,294,967,295
u640 to 18,446,744,073,709,551,615
  • Each width and sign will be its own type. AEL will never convert one to another silently: converting will be an explicit operation that reports a value out of range (see Errors and checked arithmetic).
  • An integer literal will take the type its place expects, and will be an i64 when nothing says otherwise.
  • Arithmetic will be checked: an overflow will be reported, never silently wrapped.

Booleans and unit

  • bool will have the two values true and false. It will not be an integer, and an integer will never be a condition.
  • (), the unit type, will have one value, also written (). It will mean "no value": a function that returns nothing will return unit.

There will be no null value: a value that may be missing will have the type Option<T>.

Arrays

[T; N] will be a fixed array of exactly N values of type T. Its length will be part of its type.

Preview syntax — may change before launch
let scores: [i64; 3] = [12, 7, 30];
let best: i64 = scores[2];

Every index will be checked against the length. [] will be an array of length zero, and will need a type such as [i64; 0] from its context.

Structs

A struct will group named fields. You will build one by naming the struct and giving every field, in the order the struct declares them.

Preview syntax — may change before launch
struct Point {
    x: i64,
    y: i64,
}

fn total(p: Point) -> i64 {
    return p.x + p.y;
}

fn example() -> i64 {
    let p: Point = Point(2, 3);
    return total(p);
}
  • Fields will be read with .: p.x. A field of a let mut binding will be assignable: p.x = 5;.
  • A struct will not be able to contain itself, directly or through its fields.

Enums

An enum will be one of several variants, and a variant will be able to carry values.

Preview syntax — may change before launch
enum Reply {
    Empty,
    Text(Str<200>),
    Code(u16, Str<40>),
}

fn example() -> Reply {
    return Reply::Code(404, "not found");
}
  • A variant will always be written with its enum's name: Reply::Text(…). A variant without values will itself be a value: Reply::Empty.
  • You will take an enum apart with match, which will have to handle every variant; see Control flow.

Option and Result

Two enums will be built in:

TypeVariantsUse
Option<T>Option::Some(value), Option::NoneA value that may be missing.
Result<T, E>Result::Ok(value), Result::Err(error)The result of anything that can fail. AEL will have no exceptions.

Errors and checked arithmetic shows how to return and handle a Result.

Bounded text

Str<N> will be UTF-8 text of at most N bytes.

  • A text literal will have to fit: let name: Str<8> = "a longer name"; will fail when you check your code, not when it runs.
  • The length of text will be counted in bytes. Reading one byte of text will return a Result, checked against the length.
  • Text will have no index operator, no slices and no character indexing: a byte will never be taken for a whole character.
  • Adding to text that has no room left will return an error and leave the text unchanged.

Bounded lists

Vec<T, N> will be a list of at most N values of type T.

  • A list will start empty, with room for N values.
  • Adding a value to a full list will return an error that gives the value back, and the list will stay unchanged.
  • Removing at an index that does not exist will return an error, and the list will stay unchanged.
  • list[i] will be checked against the number of values the list holds.

The operations on text and lists will belong to the standard library: see Text and collections.

References

&T will be a shared reference to a value and &mut T an exclusive one. Ownership describes when you will be able to create and use them.

Type aliases

type will give a type a second name; the two names will mean the same type.

Preview syntax — may change before launch
type OrderId = u64;
type Lines = Vec<OrderId, 16>;

Equality

== and != will compare two integers of the same type, or two booleans. Structs, enums, text and lists will not be compared with ==: you will compare their parts.

Built-in error types

Four error enums will be built in, CapacityError, IndexError, CastError and StringError, for full collections, missing indexes, integer conversions and invalid text. Errors and checked arithmetic lists their variants.

Not in the preview

These are not part of the preview syntax: floating-point and fixed-point numbers, the machine-sized integers usize and isize, generic types of your own, traits, closures and functions used as values. How a type declared in one file will be used from another file will be confirmed when the syntax is final.