Standard Library
Modules written in Logos itself. Import with use at the top of your script.
These modules provide functional programming utilities, math algorithms, and more.
std/array
Import with use "std/array" at the top of your script.
Functional array operations. These work on arrays of any type, making data transformations
declarative and readable.
map(arr, fn) Transform each element, return new arrayfilter(arr, fn) Keep elements where fn returns truereduce(arr, fn, init) Combine to single value using fn(acc, val)unique(arr) Remove duplicate valuessum(arr) Sum all numeric elementsmin(arr) Smallest elementmax(arr) Largest elementindexOf(arr, val) Position of val, or -1 if not founduse "std/array"
let nums = [1, 2, 3, 4, 5]
// Transform each element
let doubled = map(nums, fn(x) -> x * 2)
// [2, 4, 6, 8, 10]
// Keep only elements matching a condition
let evens = filter(nums, fn(x) -> x % 2 == 0)
// [2, 4]
// Combine all elements into one value
let total = reduce(nums, fn(acc, x) -> acc + x, 0)
// 15
// Remove duplicates
let withDupes = [1, 2, 2, 3, 3, 3]
let unique = unique(withDupes)
// [1, 2, 3]
// Math on arrays
sum(nums) // 15
min(nums) // 1
max(nums) // 5
// Find position
indexOf(nums, 3) // 2 (0-based)
indexOf(nums, 99) // -1 (not found)std/math
Import with use "std/math" at the top of your script.
Math utilities, number theory, and statistics. Great for algorithmic tasks without importing
external libraries.
mathFactorial(n) n! (1 * 2 * ... * n)mathFib(n) nth Fibonacci number (0-indexed)mathIsPrime(n) true if n is primemathGcd(a, b) Greatest common divisormathLcm(a, b) Least common multiplemathMean(arr) Average of numbers in arraymathMedian(arr) Middle value (sorted)mathClamp(n, min, max) n if in range, else min/maxuse "std/math"
// Factorial and Fibonacci
mathFactorial(5) // 120
mathFib(10) // 55
// Prime checking
mathIsPrime(17) // true
mathIsPrime(15) // false
// Number theory
mathGcd(48, 18) // 6 (greatest common divisor)
mathLcm(4, 6) // 12 (least common multiple)
// Statistics
let scores = [85, 90, 78, 92, 88]
mathMean(scores) // 86.6
mathMedian(scores) // 88
// Number theory utilities
mathClamp(15, 0, 10) // 10 (constrain to range)
mathLerp(0, 100, 0.25) // 25.0 (linear interpolation)std/string
Import with use "std/string" at the top of your script.
String manipulation for formatting, analysis, and transformation. Complement to the built-in
string functions.
strCapitalize(s) Capitalize first letter of each wordstrReverse(s) Reverse all charactersstrIsPalindrome(s) true if reads same forwards/backwardsstrIsEmpty(s) true if string is emptystrCount(s, sub) Count occurrences of sub in sstrPadStart(s, len, c) Pad s to len with c at startstrPadEnd(s, len, c) Pad s to len with c at enduse "std/string"
// Case manipulation
strCapitalize("hello world") // "Hello World"
strReverse("hello") // "olleh"
// String analysis
strIsPalindrome("racecar") // true
strIsEmpty("") // true
strCount("banana", "a") // 3
// Padding (useful for alignment)
strPadStart("42", 6, "0") // "000042"
strPadEnd("hi", 6, ".") // "hi...."std/path
Import with use "std/path" at the top of your script.
Cross-platform path manipulation. Handles separators and normalization automatically.
pathJoin(parts) Join array of path componentspathBase(p) Filename without directorypathDir(p) Directory portion of pathpathExt(p) Extension including dotpathWithoutExt(p) Path without extensionpathIsAbs(p) true if absolute pathpathExists(p) true if file/dir existsuse "std/path"
let p = "/home/user/docs/report.pdf"
// Break path into parts
pathBase(p) // "report.pdf"
pathDir(p) // "/home/user/docs"
pathExt(p) // ".pdf"
pathWithoutExt(p) // "/home/user/docs/report"
// Build paths
let dir = pathJoin(["home", "user", "docs", "files"])
// "home/user/docs/files"
// Path analysis
pathIsAbs("/home/user") // true
pathIsAbs("relative") // false
pathExists("/etc/passwd") // truestd/time
Import with use "std/time" at the top of your script.
Date and time handling. datetimeNow() returns a table with date, str, and ts (Unix timestamp) keys.
datetimeNow() Current datetime as tabledatetimeAdd(dt, n, unit) Add n units (days/hours/etc)datetimeSubtract(dt, n, unit) Subtract n unitsdatetimeDiff(d1, d2, unit) Difference in specified unitdatetimeFormat(dt, fmt) Format with Go time layoutdatetimeIsAfter(d1, d2) true if d1 is lateruse "std/time"
// Get current time
let now = datetimeNow()
print(now["date"]) // "2026-03-19"
print(now["str"]) // "2026-03-19 15:04:05"
// Time arithmetic
let tomorrow = datetimeAdd(now, 1, "days")
let nextWeek = datetimeAdd(now, 7, "days")
let yesterday = datetimeSubtract(now, 1, "days")
// Time differences
let diff = datetimeDiff(tomorrow, now, "days") // 1
// Comparison
datetimeIsAfter(tomorrow, now) // true
datetimeIsBefore(yesterday, now) // true
datetimeIsEqual(now, now) // true
// Formatting (Go time format)
datetimeFormat(now, "January 2, 2006") // "March 19, 2026"
datetimeFormat(now, "02/01/2006") // "03/19/2026"
datetimeFormat(now, "3:04 PM") // "3:04 PM"std/log
Import with use "std/log" at the top of your script.
Colored, timestamped log messages. Useful for CLI tools and background scripts where you
want structured output.
logDebug(msg) Debug level — whitelogInfo(msg) Info level — greenlogWarn(msg) Warning level — yellowlogError(msg) Error level — reduse "std/log"
// Log levels with timestamps
logDebug("Debug info") // white output
logInfo("Server started") // green output
logWarn("Low memory") // yellow output
logError("Connection failed") // red output
// Output:
// [2026-03-19 15:04:05] [DEBUG] Debug info
// [2026-03-19 15:04:05] [INFO] Server startedstd/type
Import with use "std/type" at the top of your script.
Runtime type checking. Useful for type-safe utilities and handling mixed-type data.
isString(val) Check if stringisInt(val) Check if integerisFloat(val) Check if floatisNumber(val) Check if int or floatisBool(val) Check if booleanisArray(val) Check if arrayisTable(val) Check if tableisCallable(val) Check if functionuse "std/type"
let val = 42
// Check types at runtime
isInt(val) // true
isFloat(val) // false
isNumber(val) // true (covers int and float)
isString(val) // false
isBool(val) // false
isNull(null) // true
isArray([1,2,3]) // true
isTable(table{}) // true
isCallable(fn() {}) // true
// Use for type-safe code
fn process(val) {
if isArray(val) {
// handle array
} else if isString(val) {
// handle string
}
}std/testing
Import with use "std/testing" at the top of your script.
Simple test framework. Group assertions with suite, run with summary.
Prints a report showing which tests passed or failed.
assert(name, got, expected) Check equality, report on mismatchsuite(name, fn) Group related assertionssummary() Print test resultsuse "std/testing"
// Group related tests
suite("string utils", fn() {
assert("reverse", strReverse("hello"), "olleh")
assert("capitalize", strCapitalize("hello"), "Hello")
assert("palindrome", strIsPalindrome("racecar"), true)
})
suite("math utils", fn() {
assert("factorial", mathFactorial(5), 120)
assert("fibonacci", mathFib(10), 55)
assert("prime", mathIsPrime(17), true)
})
// Run all tests and show summary
summary()