Skip to content

Instantly share code, notes, and snippets.

@0x00b1
Last active December 18, 2018 19:50
Show Gist options
  • Save 0x00b1/df530459b8abf5fd57789ff6c15b8ad6 to your computer and use it in GitHub Desktop.
Save 0x00b1/df530459b8abf5fd57789ff6c15b8ad6 to your computer and use it in GitHub Desktop.

Primitive data type

A scalar type represents a single value. Ox has three primitive scalar types:

  • Boolean,
  • Floating-point, and
  • Integer.

Boolean data type

The Boolean data type represents the two truth values (true and false) of Boolean algebra.

Syntax

BOOLEAN LITERAL = “true” | “false”;

Floating-point

Size Signedness
16-bit Floating-point 16-bit signed
32-bit Floating-point 32-bit signed
64-bit Floating-point 64-bit signed

Syntax

FLOATING POINT LITERAL = ...;

Integer

Size Signedness
unsigned 8-bit Integer 8-bit unsigned
8-bit Integer 8-bit signed
unsigned 16-bit Integer 16-bit unsigned
16-bit Integer 16-bit signed
unsigned 32-bit Integer 32-bit unsigned
32-bit Integer 32-bit signed
unsigned 64-bit Integer 64-bit unsigned
64-bit Integer 64-bit signed
unsigned 128-bit Integer 128-bit unsigned
128-bit Integer 128-bit signed
unsigned Integer Arbitrary-precision unsigned
Integer Arbitrary-precision signed

Syntax

INTEGER LITERAL = ...;

Compound data type

A compound data type groups multiple values into one type.

Array

An array is a homogenous sequence:

a: [4 × unsigned 8-bit Integer] ← [0, 0, 0, 0];

Multi-dimensional arrays

a: [(2 × 4) × Integer] ← [[0, 0, 0, 0], [0, 0, 0, 0]];

Indexing notation

a: [4 × unsigned 8-bit Integer] ← [1, 2, 3, 4];

a[0]; # 1

a[1]; # 2

b: [(2 × 4) × Integer] ← [[1, 2, 3, 4], [1, 2, 3, 4]];

b[0, 0] # 1

b[0, 1] # 2

b[:, 0] # [1, 1]

b[0, :] # [1, 2, 3, 4]

Syntax

ARRAY-TYPE = “[” SHAPE “×” TYPE “]”;

Tuple

A tuple is a heterogeneous sequence:

example: (unsigned 8-bit Integer, Boolean, Boolean) ← (0, true, true);

Anonymous function

Syntax

ANONYMOUS-FUNCTION = “λ” PARAMETERS "{" EXPRESSION "}";

Closure

Example

subroutine example {a: Integer} → Integer {
    return λ {b} {
        a + b;
    }
}

x: Integer ← example(1)(1); # 2

Operator

Unary operation

Syntax

UNARY-OPERATION = "{" PARAMETER "}" “→” TYPE “{“ EXPRESSION “}”;

Binary operation

Syntax

BINARY-OPERATION = "{" PARAMETER "," PARAMETER "}" “→” TYPE “{“ EXPRESSION “}”;

Infix

Syntax

“infix” “operator” OPERATOR BINARY-OPERATION;

Example

infix operator + {a: Integer, b: Integer} → Integer {
  …
}

x: Integer ← 1 + 1;

Prefix

Syntax

“prefix” “operator” OPERATOR UNARY-OPERATION;

Example

prefix operator ¬ {a: Boolean} → Boolean {
  …
}

x: Boolean ← ¬true;

Postfix

Syntax

“postfix” “operator” OPERATOR UNARY-OPERATION;

Example

postfix operator ! {a: Integer} → Integer {
  …
}

x: Integer ← 5!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment