Types

Overview

[1]I.e. anywhere that a CellSet is required, a Cell is accepted as well. All operations on a CellSet are also allowed on a Cell. See https://en.wikipedia.org/wiki/Subtyping.

See Subtype coercion for more about subtypes.

See Variable typing regarding how variables use the type system.

Primitive types

Int
Status:Fully implemented
Methods:Int methods
Operators:Arithmetic operators, Bitwise operators, Comparison operators

An integer, represented using a 64-bit signed two’s complement integer. This means the minimum value is -9223372036854775808 and the maximum value is 9223372036854775807.

Boolean values are represented using integers. (See Boolean conversion.)

An integer literal consists of a sequence of digits without a leading zero but with an optional + or - at the beginning. Examples:

  • 0
  • -1
  • 42
  • +6
  • -32768
Cell
Status:Fully implemented
Methods:Cell methods
Operators:Set operators, Comparison operators (== and != only)
Subtype of:CellSet

A cell state, represented using an 8-bit unsigned integer. This means the minimum value is 0 and the maximum value is 255, so an automaton cannot have more than 256 states. Cell values are always within the range of valid cell states in a cellular automaton. For example, an automaton with 10 states has a maximum cell state ID of 9.

Cell is a subtype of CellSet. When used in place of a CellSet, a Cell represents a set containing only the one cell state.

A Cell literal consists of the # operator followed by the cell state ID. Examples:

  • #0
  • #1
  • #42

A Cell literal may use an arbitrary integer expression for the cell state ID by surrounding the expression in parentheses. Examples:

  • #(my_variable)
  • #(x + 5)
Tag
Status:Not yet implemented

This type’s design is still a work in progress.

String
Status:Partially implemented

Different String values are different types, and therefore cannot be stored in the same variable. (See Why are some collections with different contents considered different types?)

This type’s design is still a work in progress.

Collection types

Vec
Status:Fully implemented
Methods:Vec methods
Operators:Arithmetic operators, Bitwise operators, Comparison operators, Vector indexing

A vector, represented using a fixed-length array of Int values. Each Int value is a component of the Vec, and the number of components is the length of the Vec. The length of a Vec must be between 1 and 256 (inclusive). Vec values of different lengths are different types, and therefore cannot be stored in the same variable.

The first component of a Vec is the X component at index 0; the second is the Y component at index 1; etc.

A Vec literal consists of a list of integer expressions separated by commas surrounded by square brackets. Examples:

  • [3, -1, 0] is a Vec of length 3 with X component 3, Y component -1, Z component 0
  • [6] is a Vec of length 1 with X component 6
  • [a, b] is a Vec of length 2 with X compoment a and Y component b, given a and b are integers

A Vec literal may contain other vectors, which are concatenated to produce the result. Examples:

  • [v1, -3, v2] is a Vec constructed by concatenating v1, [-3], and v2

A Vec can also be constructed using vec() and its variants.

Pattern
Status:Partially implemented

A configuration of cells. Patterns with different shapes are different types.

Set/filter types

IntSet
Status:Implementation in progress
Operators:Set operators

A finite set of Int. Different IntSet values are different types, and therefore cannot be stored in the same variable. (See Why are some collections with different contents considered different types?)

An IntSet literal consists of a comma-separated list of Int or IntSet surrounded by curly braces. Examples:

  • {} constructs the empty set, containing no integers
  • {42} constructs a set containing only the integer 42
  • {1, 2, 3, 4} constructs a set containing the integers 1, 2, 3, and 4
  • {1, 2, 3, 4,} is also allowed (but discouraged unless spanning multiple lines)

An IntSet can also be constructed using a range literal consisting of two integers separated by ... Examples:

  • 1..5 is equivalent to {1, 2, 3, 4, 5}
  • -3..+3 contains all integers from -3 to 3 (inclusive)
  • {-4..-1, 1..99} contains all integers from -4 to 99 (inclusive) except 0
VecSet
Status:Implementation in progress
Operators:Set operators

A finite set of Vec, all with the same length. Different VecSet values are different types, and therefore cannot be stored in the same variable. (See Why are some collections with different contents considered different types?)

CellSet
Status:Partially implemented

A set of cell states. Unlike IntSet and VecSet, all CellSet values are the same type.

This type’s design is still a work in progress.

PatternFilter
Status:Not yet implemented

Different PatternFilter values are different types, and therefore cannot be stored in the same variable. (See Why are some collections with different contents considered different types?)

This type’s design is still a work in progress.