Examples Gallery
Real-world examples demonstrating Suji’s capabilities.
Overview
Each example includes:
- Overview: What the example demonstrates
- Complete Code: Full working implementation
- Step-by-Step Explanation: Detailed breakdown
- Variations: Alternative approaches
- Exercises: Practice challenges
- See Also: Related concepts and examples
Every code block in this section is a complete program. Copy one into example.si and run suji example.si — blocks that need input create it in a temp file first.
Example Categories
Algorithms
- Fibonacci Sequence - Recursion, memoization and the limits of both
- Quicksort - Divide and conquer with pattern matching and list slices
Functional Programming
- Function Composition - Composing and chaining functions
Text Processing
- Regex Matching - Pattern matching for text processing
Automation
- CLI Tools - Building command-line utilities
Task-oriented recipes for files, data formats, configuration and shell scripting live in the Cookbook.
Quick Examples
Hello World
import std:println
println("Hello, Suji!")
Calculate Factorial
import std:println
factorial = |n| {
match n {
0 | 1 => 1,
_ => n * factorial(n - 1),
}
}
println(factorial(5)) # 120
Every match arm whose body is a bare expression needs a trailing comma — including the last one.
Filter and Transform a List
import std:println
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
filtered = numbers::filter(|n| n % 2 == 0)
result = filtered::map(|n| n * n)
println(result) # [4, 16, 36, 64, 100]
Read and Parse JSON
import std:io
import std:json
import std:os
import std:println
path = `mktemp`
f = io:open(path, true, true)
f::write("""{"users": [{"name": "Alice"}, {"name": "Bob"}]}""")
f::close()
file = io:open(path)
data = json:parse(file::read_all())
file::close()
println("Loaded ${data:users::length()} users") # Loaded 2 users
os:rm(path)
Run a Shell Command
import std:println
# Backticks return stdout with the trailing newline trimmed
println(`echo hello from the shell`) # hello from the shell
# A non-zero exit ends the script, so absorb failures in the shell itself
println(`grep nothing /etc/hosts || echo "no match"`) # no match
Getting Started
- Browse examples by category
- Read the overview and prerequisites
- Study the complete code
- Review the step-by-step explanation
- Try the exercises
- Experiment with variations
See Also
- Cookbook - Task-oriented recipes
- Standard Library - Built-in modules
- Functions - Function programming guide