Language Guide
Language Basics
Required version: Sponge >=1.0.0
Variables and Declarations
Let Binding
Declare immutable variables with let:
let name = "Sponge";
let age = 5;
let pi = 3.14159;
let is_fun = true;Variable Assignment
Update variable values:
let x = 10;
x = 20; # assignmentCompound Assignment
Shorthand operators for common operations:
let count = 5;
count += 3; # count = count + 3
count -= 1; # count = count - 1
count *= 2; # count = count * 2
count /= 4; # count = count / 4Data Types
Sponge supports several built-in types:
| Type | Example | Description |
|---|---|---|
| Number | 42 | Integer values |
| Float | 3.14 | Floating-point numbers |
| String | "hello" | Text data |
| Boolean | true, false | Logical values |
| Array | [1, 2, 3] | Ordered collections |
| Dictionary | {a: 1, b: 2} | Key-value mappings |
| Null | null | Absence of value |
Operators
Arithmetic
let a = 10 + 5; # 15
let b = 10 - 3; # 7
let c = 4 * 5; # 20
let d = 20 / 4; # 5
let e = 17 % 5; # 2
let f = 2 ** 3; # 8 (power)Comparison
let eq = 5 == 5; # true
let neq = 5 != 3; # true
let lt = 3 < 5; # true
let gt = 5 > 3; # true
let lte = 5 <= 5; # true
let gte = 5 >= 3; # trueLogical
let a = true and false; # false
let b = true or false; # true
let c = not true; # falseString Operations
String Concatenation
let greeting = "Hello" + " " + "World";
print(greeting); # Hello WorldString Functions
let text = "Sponge";
print(len(text)); # 6
print(upper(text)); # SPONGE
print(lower(text)); # sponge
print(slice(text, 0, 4)); # Spon
print(contains(text, "onge")); # trueString Splitting
let parts = split("a,b,c", ",");
print(parts); # [a, b, c]Comments
# Single-line comment
/* Multi-line
comment */