# Raw types:
# - int / uint (default size), int8, uint8, 16, 32, 64, bigint (arbitrary precision)
# (1, 2, 3… are int)
# - rational (bigint numerator, uint64 denominator), bigrational (arbitrary precision)
# (0.3, 1/12… are rational)
# - real (default size), real64, real128
# (1e10 is real)
# Arrays are fixed-width sequences of items of a given type. Typically stored on the stack.
daysPerMonth: array uint8 size 12
daysPerMonth[0] = 31
# Lists are sequences of items of a given type. They can be increased on-demand.
dailySharePrice: [2.5, 13.0, 16.1, 15.7]
dailySharePrice += [16.5]
# Sequences synchronously compute the next element on-demand, auto-saving previous elements.
oddNumbers = sequence uint32 start 1 get (i: uint) {i * 2 + 1} # Return nil if it is past the end of the sequence.
oddNumbers[2] == 5
# They can automatically detect arithmetic and geometric progressions.
powersOf2 = [2, 4, 8...]
str: "This is some text." # string, a data structure that includes a list of uint8.
# Types glue together multiple types.
color = type
r: uint8 # 0 by default.
g: uint8
b: uint8
a: uint8 255
# You can instantiate a type.
orange: color {r: 255, g: 128}
orange
coord2d = type
x: uint32
y: uint32
pixel = type
import coord2d
import color
# Overlapping types: the value is only of one of several types.
def divide (a: int) by (b: int) return (either error or int)
if (b == 0) then
error "Division by zero"
else
a / b
# References: overlapping types used to manipulate refcounted heap pointers.
linkedListNode = type (content: type)
prev: ref linkedListNode
next: ref linkedListNode
value: content
linkedList = ref linkedListNode
head: linkedListNode # instances start out with the first type, here empty.
if (head is pointer) then
# do something with it
else
# head is nil
algebra = class (set: type)
def add set to set return set
def remove set to set return set
def negate set return set
def multiply set by set return set
def divide set by set return (either error or set)