Quick Start¶

This page demonstrates the core language features in the shortest practical path. For a full treatment of each topic, follow the links into the Language Guide.


Hello, World¶

Save the following to hello.sym and run it with symbolic hello.sym:

print("Hello, World!");

The Interactive REPL¶

Start the REPL with no arguments:

symbolic

The REPL supports syntax highlighting, tab completion, and multi-line input. Use arrow keys to navigate history. Special commands begin with %:

Command

Description

%help

Display help and a list of available commands

%version

Print the runtime version

%magic

List all REPL magic commands

%clear

Clear the terminal screen

%history

Show the command history for this session

%exit

Exit the REPL


Variables and Literals¶

# Integers, floats, complex numbers
n        = 42
pi_approx = 3.14159
z         = 3 + 4i
big       = 1_000_000
sci       = 6.022e23
hex_val   = 0xFF
bin_val   = 0b1010

# Strings
name      = "Alice"
raw       = r"C:\Users\name"
multiline = """
Line one
Line two
"""

# Interpolation
greeting  = f"Hello, {name}! n is {n}."

# Collections
nums  = [1, 2, 3, 4, 5]
point = (10, 20)
tags  = {"alpha", "beta", "gamma"}
cfg   = {"host": "localhost", "port": 8080}

Functions¶

Three syntactic forms are available, each suited to different contexts:

# Keyword form — explicit body, supports full statements
fn add(x, y) {
    return x + y;
}

# Algebraic form — implicit return, mirrors mathematical notation
square(x) = x ^ 2

# Lambda form — anonymous, for use as values
double = ((x) -> x * 2)

# With type annotations and contract clauses
fn divide(a: Integer, b: Integer) -> Fraction
    requires b != 0
    ensures result * b == a {
    return a / b;
}

# Async function
async fn fetch(url) {
    response = await http.get(url);
    return response.json();
}

Control Flow¶

# Conditionals
if x > 0 {
    print("positive");
} else if x < 0 {
    print("negative");
} else {
    print("zero");
}

# Inline ternary
label = x >= 0 ? "non-negative" : "negative"

# While loop
while i < 10 {
    i += 1;
}

# For-in loop (iterator style)
for item in [1, 2, 3, 4, 5] {
    print(item);
}

# Range loop with exclusive upper bound
for i in 0..<10 {
    print(i);
}

# C-style loop: initializer, condition, step
for i = 0, i < 10, 1 {
    print(i);
}

# Infinite loop
loop {
    if done { stop; }
}

# Repeat-until (do-while equivalent)
repeat {
    x += 1;
} until x >= 100;

Pattern Matching¶

fn classify(value) {
    match value {
        Number(n) if n > 0  => f"{n} is positive";
        Number(0)           => "zero";
        Number(n)           => f"{n} is negative";
        String(s)           => f"string: {s}";
        [head, *tail]       => f"list starting with {head}";
        _                   => "unknown"
    }
}

Error Handling¶

# Structured try-catch
try {
    result = risky_operation();
} catch err {
    ValueError        { print(f"Value error: {err}"); }
    ZeroDivisionError { print("Division by zero"); }
    _                 { print(f"Unexpected: {err}"); }
}

# Try operator — inline fallback
value = try parse_int(input) ?? 0

Classes¶

class Point extends (Object) {
    fn __init__(self, x, y) {
        self.x = x;
        self.y = y;
    }

    fn distance_to(self, other) {
        dx = self.x - other.x;
        dy = self.y - other.y;
        return (dx^2 + dy^2).sqrt();
    }

    static fn origin() = Point(0, 0)
}

p1 = Point(3, 4)
p2 = Point.origin()
print(p1.distance_to(p2))    # 5

Imports¶

import math;
import math::integration;
import math::functions::{sin, cos, exp};
import math::constants::*;
import math::integration as integ;

Mathematical Domains¶

The domain math block enables extended mathematical syntax:

domain math {
    @var x

    # Equation and derivative
    @equ x^2 - x - 2 == 0
    @d/dx sin(x^2)

    # Definite integral: ∫₀¹ x² dx
    @integral [x=0 to 1] x^2, dx

    # Summation: Σ k² for k=1..n
    @sum {k=1}^{n} k^2

    # Matrix
    A = @matrix [[1, 2], [3, 4]]
}

Next Steps¶

Syntax

Complete syntax reference: literals, operators, comments, identifiers

<no title>

All function forms, parameters, closures, contracts

<no title>

Structural, type, and guard patterns; exhaustiveness

<no title>

Built-in numeric types, strings, collections, and the type system

<no title>

Worked examples using the mathematics standard library2