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!

String Operations

Weir provides built-in string operations for construction, inspection, and transformation.

"hello, world"
"line one\nline two"
"" ;; empty string

str is variadic — it concatenates any number of values into a string, converting each via its Show representation:

(str "Hello, " name "!") ;; => "Hello, Alice!"
(str "x=" x " y=" y) ;; => "x=5 y=10"
(str "score: " (+ base bonus)) ;; => "score: 42"

Returns the length of a string:

(string-length "hello") ;; => 5
(string-length "") ;; => 0
(string-length "emoji: hi") ;; => 9

Returns the character code (integer) at a given index:

(string-ref "hello" 0) ;; => 104 (ASCII 'h')
(string-ref "ABC" 1) ;; => 66 (ASCII 'B')

Checks if a string contains a substring:

(string-contains "hello world" "world") ;; => true
(string-contains "hello world" "xyz") ;; => false
(string-contains "hello" "") ;; => true

The generic len function also works on strings:

(len "hello") ;; => 5

Extracts a substring from start index (inclusive) to end index (exclusive):

(substring "hello world" 0 5) ;; => "hello"
(substring "hello world" 6 11) ;; => "world"
(substring "abcdef" 2 4) ;; => "cd"

Converts all characters to uppercase:

(string-upcase "hello") ;; => "HELLO"
(string-upcase "Hello World") ;; => "HELLO WORLD"

Converts all characters to lowercase:

(string-downcase "HELLO") ;; => "hello"
(string-downcase "Hello World") ;; => "hello world"

Removes leading and trailing whitespace:

(string-trim " hello ") ;; => "hello"
(string-trim "\n spaced \t") ;; => "spaced"

Converts a character code (integer) to a single-character string:

(char-to-string 65) ;; => "A"
(char-to-string 104) ;; => "h"
(char-to-string 10) ;; => "\n"
FunctionSignatureDescription
str(Fn ['a ...] String)Concatenate values into a string
string-length(Fn [String] i64)Length of string
substring(Fn [String i64 i64] String)Extract substring (start, end)
string-ref(Fn [String i64] i64)Character code at index
string-contains(Fn [String String] Bool)Substring search
string-upcase(Fn [String] String)To uppercase
string-downcase(Fn [String] String)To lowercase
string-trim(Fn [String] String)Trim whitespace
char-to-string(Fn [i64] String)Char code to string