Types

int

Integers. Supports decimal, hex (0xFF), and binary (0b1010) literals.

lhj
forge a = 42
forge b = 0xFF      ## 255
forge c = 0b1010    ## 10
forge d = -7

float

IEEE 754 double-precision. Supports scientific notation.

lhj
forge pi    = 3.14159
forge tiny  = 1e-6
forge big   = 2.5e8

str

Strings use double quotes. Single quotes are not supported. String interpolation with {expr} is built in:

lhj
forge name = "Aria"
echo "Hello, {name}!"                  ## Hello, Aria!
echo "2 + 2 = {2 + 2}"                ## 2 + 2 = 4
echo "HP: {warrior.hp}"               ## HP: 100

Any expression works inside {}.

String operations

lhj
forge s = "hello"

echo s + " world"       ## hello world
echo s * 3              ## hellohellohello
echo len(s)             ## 5
echo s[0]               ## h
echo s[1:3]             ## el

list

Ordered mutable sequences.

lhj
forge nums  = [1, 2, 3, 4, 5]
forge mixed = [1, "two", yep, zilch]
forge empty = []

echo nums[0]            ## 1
echo nums[-1]           ## 5
echo len(nums)          ## 5

nums.pack(6)            ## append
echo nums               ## [1, 2, 3, 4, 5, 6]

Slicing:

lhj
echo nums[1:3]          ## [2, 3]
echo nums[:2]           ## [1, 2]
echo nums[3:]           ## [4, 5, 6]

dict

Key-value maps. Keys can be any hashable type.

lhj
forge person = {
    "name": "Aria",
    "hp":   100,
    "alive": yep
}

echo person["name"]     ## Aria
person["hp"] <- 80

## nested access
forge data = {"stats": {"strength": 12}}
echo data["stats"]["strength"]   ## 12

yep / nope

Boolean values.

lhj
forge flag = yep
forge done = nope

echo flag and nope      ## nope
echo flag or  nope      ## yep
echo not flag           ## nope

zilch

The null value. Used when there's no meaningful value to return.

lhj
forge x = zilch
echo x          ## zilch

blade maybe():
    ## implicitly returns zilch
    echo "no return statement"

echo maybe()    ## zilch

Ranges

The .. operator creates an inclusive integer range:

lhj
march i in 1..5:
    echo i       ## 1 2 3 4 5

forge r = 1..10
echo r[0]        ## 1
echo len(r)      ## 10

Ranges work in march loops, slicing, and anywhere a list is expected.

Type checking

Use type() to get the type name as a string:

lhj
echo type(42)       ## int
echo type("hi")     ## str
echo type([])       ## list
echo type({})       ## dict
echo type(yep)      ## bool
echo type(zilch)    ## zilch

Type conversion

lhj
echo int("42")      ## 42
echo str(100)       ## "100"
echo float("3.14")  ## 3.14
echo list("abc")    ## ["a", "b", "c"]