Skip to content

Hello! 👋 My name is Nathan Weir. This is a fun personal project for using AI to build a bespoke, domain-specific programming language. It is not a serious, professional project. This site and the language itself are largely generated via Claude Code. If you find yourself programming with Weir, have fun - but use at your own risk!

Collections

Weir provides two collection types with literal syntax: vectors (ordered, indexed) and hash-maps (key-value).

Vectors are ordered, indexed collections created with square bracket literals:

[1 2 3 4 5]
["hello" "world"]
[] ;; empty vector

Vectors are typed — all elements must have the same type. The element type is inferred from contents:

(let ((nums [1 2 3]) ;; (Vector i64)
(names ["alice" "bob"])) ;; (Vector String)
...)

Returns the number of elements:

(len [1 2 3]) ;; => 3
(len []) ;; => 0

Gets the element at an index (zero-based):

(nth [10 20 30] 0) ;; => 10
(nth [10 20 30] 2) ;; => 30

Returns a new vector with an element added at the end:

(append [1 2] 3) ;; => [1 2 3]
(append [] "hello") ;; => ["hello"]

Returns a new vector with the element at an index replaced:

(set-nth [1 2 3] 1 99) ;; => [1 99 3]

Vectors are immutable — append and set-nth return new vectors, leaving the original unchanged:

(let ((v [1 2 3])
(v2 (append v 4)))
(println (len v)) ;; => 3 (unchanged)
(println (len v2))) ;; => 4

Vectors work with closures and higher-order patterns:

;; Map a function over positions
(map .pos enemies)
;; Filter with a predicate
(filter (fn (e) (> (.health e) 0)) enemies)

For bulk processing, parallel versions are available:

(par-map update-position entities)
(par-for-each process-chunk chunks)

See Built-in Functions — Concurrency for details.

Hash-maps are unordered key-value collections created with curly brace literals. Keys are typically keywords:

{:name "Alice"
:health 100
:pos (Vec2 0.0 0.0)}
{} ;; empty map

Maps can be nested:

{:player {:name "Alice" :level 5}
:enemies [(spawn-goblin) (spawn-orc)]}

Returns the number of entries:

(len {:a 1 :b 2 :c 3}) ;; => 3
FunctionSignatureDescription
len(Fn ['a] i64)Length of vector, map, or string
nth(Fn [(Vector 'a) i64] 'a)Get element at index
append(Fn [(Vector 'a) 'a] (Vector 'a))Append element
set-nth(Fn [(Vector 'a) i64 'a] (Vector 'a))Replace element at index
par-map(Fn [(Fn ['a] 'b) (Vector 'a)] (Vector 'b))Parallel map
par-for-each(Fn [(Fn ['a] Unit) (Vector 'a)] Unit)Parallel for-each
SyntaxMeaning
(f x y)S-expression — function call
[x y z]Vector literal
{:k1 v1 :k2 v2}Hash-map literal

Parentheses are always code. Square brackets and curly braces are always data.