Types¶
Overview¶
- There are two important primitive types:
IntandCell - Each of these two primitive types has a collection type:
Vec(collection ofInt) andPattern(collection ofCell) - Each of these four types has a corresponding set/filter type:
IntSet,CellSet,VecSet, andPatternFilterCellis a subtype [1] ofCellSetPatternis a subtype ofPatternFilter
- There are two other primitive types:
TagandString
| [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
-9223372036854775808and the maximum value is9223372036854775807.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-142+6-32768
-
Cell¶ Status: Fully implemented Methods: Cell methods Operators: Set operators, Comparison operators ( ==and!=only)Subtype of: CellSetA cell state, represented using an 8-bit unsigned integer. This means the minimum value is
0and the maximum value is255, so an automaton cannot have more than 256 states.Cellvalues 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 of9.Cellis a subtype ofCellSet. When used in place of aCellSet, aCellrepresents a set containing only the one cell state.A
Cellliteral consists of the#operator followed by the cell state ID. Examples:#0#1#42
A
Cellliteral 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
Stringvalues 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
Intvalues. EachIntvalue is a component of theVec, and the number of components is the length of theVec. The length of aVecmust be between 1 and 256 (inclusive).Vecvalues of different lengths are different types, and therefore cannot be stored in the same variable.The first component of a
Vecis the X component at index 0; the second is the Y component at index 1; etc.A
Vecliteral consists of a list of integer expressions separated by commas surrounded by square brackets. Examples:[3, -1, 0]is aVecof length3with X component3, Y component-1, Z component0[6]is aVecof length1with X component6[a, b]is aVecof length2with X compomentaand Y componentb, givenaandbare integers
A
Vecliteral may contain other vectors, which are concatenated to produce the result. Examples:[v1, -3, v2]is aVecconstructed by concatenatingv1,[-3], andv2
-
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. DifferentIntSetvalues are different types, and therefore cannot be stored in the same variable. (See Why are some collections with different contents considered different types?)An
IntSetliteral consists of a comma-separated list ofIntorIntSetsurrounded 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
IntSetcan also be constructed using a range literal consisting of two integers separated by... Examples:1..5is equivalent to{1, 2, 3, 4, 5}-3..+3contains 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. DifferentVecSetvalues 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
IntSetandVecSet, allCellSetvalues are the same type.This type’s design is still a work in progress.
-
PatternFilter¶ Status: Not yet implemented Different
PatternFiltervalues 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.