Overview
WolfLang is a statically-typed, interpreted programming language designed for simplicity. It features strong type checking, lexical scoping, custom data structures, and a Rust-based embeddable engine.
Key Features
- Statically typed with explicit type declarations
- Strict type checking for variables and lists
- Object-oriented patterns using
structandimpl - Module support with the
importkeyword and namespaces - Control flow (if/else, while, for) with logical operators
- Embeddable native Rust engine
Getting Started
Running WolfLang Code
WolfLang code can be executed in two ways:
1. From a File
# Save your code to a file (e.g., program.wolf)
# Then run it with:
./wolflang --file program.wolf
2. Interactive Mode
# Run the WolfLang interpreter
./wolflang
# Type your code, then type 'run()' to execute
let x: int = 10
print x
run()
Data Types
WolfLang supports strict primitive data types, generic composite types, and user-defined structs:
| Type | Keyword | Description | Example |
|---|---|---|---|
| Integer | int |
Whole numbers | 42, -15 |
| Float | float |
Floating-point numbers | 3.14, -2.5 |
| String | string |
Text data | "Hello, World!" |
| Boolean | bool |
True/False values | true, false |
| List | list<T> |
Typed collection of values | [1, 2] (as list<int>) |
| Custom | [Identifier] |
User defined structs | Point(10, 20) |
Variables
Variables in WolfLang must be declared with an explicit type followed by a colon. Lists require inner type definition using angle brackets:
# Variable declaration syntax
let <name>: <type> = <value>
let age: int = 25
let is_active: bool = true
# List Declaration (Must specify inner type)
let numbers: list<int> = [1, 2, 3, 4]
Operators
Arithmetic Operators
Supports +, -, *, / for standard arithmetic. The + operator also handles string concatenation.
Comparison Operators
WolfLang enforces that comparisons must happen between matching types.
==(Equal)!=(Not equal)>,<,>=,<=(Greater / Less than)
Logical & Unary Operators
Combine or invert conditions with boolean logic:
| Operator | Description | Example |
|---|---|---|
and |
Logical AND | true and false → false |
or |
Logical OR | true or false → true |
! |
Logical NOT / Unary Bang | !true → false |
Control Flow
If / Else Statements
Conditional execution blocks must be closed with end. You can incorporate logical operators directly.
let x: int = 10
if x > 5 and x < 20
print "x is in range"
else
print "x is out of range"
end
While Loops
let count: int = 0
while count < 5
print count
count = count + 1
end
For Loops
Iterate over a range of integer values. Note the syntax strictly follows: for int <name> = <start> range <end>.
for int i = 0 range 5
print i # Prints 0, 1, 2, 3, 4
end
Functions
Function Definition & Return
Define functions with the fn keyword. Parameters must have explicit types. Functions return values using the return keyword.
fn add(x: int, y: int)
return x + y
end
let result: int = add(5, 3)
print result # Prints 8
Structs & Impl
WolfLang provides object-oriented programming capabilities through data structures and implementation blocks.
Defining Structs
Use the struct keyword to map out custom object structures. Note that struct bodies consist of variable declarations but without initial assignment.
struct Point
x: int
y: int
end
Implementing Methods
The impl block binds functions to a specific struct. Inside these functions, instance fields are accessed via the implicit self keyword.
impl Point
fn get_x()
return self.x
end
end
Initialization & Access
Initialize a struct by calling it like a function matching the argument order of its fields.
let p: Point = Point(10, 20)
# Field Access
print p.x
# Field Re-assignment
p.y = 30
# Method Call
let current_x: int = p.get_x()
print "X is: " + current_x
Modules
Organize your codebase into multiple files. You can import variables, functions, and structs from another file into a namespace.
# Import a file and assign it an alias
import "math.wolf" as m
# Access functions or structs using the double-colon '::' operator
let res: int = m::add(5, 10)
let vec: m::Vector2 = m::Vector2(0, 1)
Lists
Create lists using square brackets and explicit type definitions.
let numbers: list<int> = [1, 2, 3]
numbers.push(4)
let last: int = numbers.pop()
let length: int = numbers.len()
Built-in Functions
I/O Functions
| Function | Description | Example |
|---|---|---|
print |
Outputs given values to standard output | print "Hello!" |
input |
Prompts the user, reads line from standard input, and returns as string | let name: string = input("Name: ") |
clear |
Clears the console display terminal | clear() |
Embeddable Engine
WolfLang can be embedded in Rust applications, allowing you to seamlessly share state, invoke native Rust closures, and execute runtime WolfLang scripts.
// Import the WolfEngine
use wolflang::WolfEngine;
let mut engine = WolfEngine::new();
// Push Rust values into WolfLang context
engine.push_int("initial_value", 42);
// Register Custom Native Functions
engine.push_fn("rust_math", |args| {
// Rust side execution...
wolflang::tokens::Token::Integer(100)
});
// Run WolfLang code
engine.run(r#"
let result: int = initial_value + rust_math()
print "Result:", result
"#).unwrap();
Examples
Interactive Application
clear()
let name: string = input("Enter your name: ")
print "Welcome to WolfLang, " + name + "!"