Syntax Overview
This page provides a comprehensive overview of JOEL syntax.
File Structure
Every JOEL file starts with an execution mode header:
[Interpreted] # or [Compiled]Optional target hint:
[target wasm32] # native, wasm32, evm, wasm-solanaComments
# Single-line comment
// Also single-line comment
/*
Multi-line comment
(coming soon)
*/Variables
let name = "JOEL" # Type inferred
let age: i32 = 24 # Explicit type
let active: bool = true # BooleanConstants
const PI: f64 = 3.14159
const MAX_SIZE: i32 = 100Functions
# Simple function
fn greet() {
print("Hello")
}
# Function with parameters
fn add(a: i32, b: i32) -> i32 {
return a + b
}
# Function with return type
fn get_name() -> str {
return "JOEL"
}Control Flow
If Statements
if condition {
# code
}
if condition {
# code
} else {
# code
}
if condition {
# code
} elif other_condition {
# code
} else {
# code
}While Loops
while condition {
# code
}For Loops
# Range-based
for i in range(0, 10) {
print(i)
}
# List iteration
let items = [1, 2, 3]
for item in items {
print(item)
}Operators
Arithmetic
let a = 10
let b = 5
a + b # Addition: 15
a - b # Subtraction: 5
a * b # Multiplication: 50
a / b # Division: 2
a % b # Modulo: 0Comparison
a == b # Equal: false
a != b # Not equal: true
a > b # Greater than: true
a < b # Less than: false
a >= b # Greater or equal: true
a <= b # Less or equal: falseLogical
true && false # AND: false
true || false # OR: true
!true # NOT: falseString Concatenation
let greeting = "Hello " + "World" # "Hello World"Data Types
Primitives
let num: i32 = 42 # 32-bit integer
let big: i64 = 1000000 # 64-bit integer
let float: f64 = 3.14 # 64-bit float
let text: str = "JOEL" # String
let flag: bool = true # BooleanCollections
# Lists
let numbers = [1, 2, 3, 4, 5]
let names = ["Alice", "Bob", "Charlie"]
# Maps (dictionaries)
let person = {
"name": "JOEL",
"age": 24
}Pattern Matching
match value {
"red" => print("Stop"),
"green" => print("Go"),
"yellow" => print("Slow"),
_ => print("Unknown"),
}Modules
module my_module
# Import other modules
import std
import ai as mlError Handling
# Result type (coming soon)
fn read_file(path: str) -> Result<Bytes, Error> {
let f = File.open(path)?
defer f.close()
return f.read_all()
}Next Steps
- Data Types - Detailed type information
- Functions - Function reference
- Control Flow - Control structures
- Operators - Complete operator reference