Skip to content
Logos / Standard Library

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 array
filter(arr, fn) Keep elements where fn returns true
reduce(arr, fn, init) Combine to single value using fn(acc, val)
unique(arr) Remove duplicate values
sum(arr) Sum all numeric elements
min(arr) Smallest element
max(arr) Largest element
indexOf(arr, val) Position of val, or -1 if not found
logos
use "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 prime
mathGcd(a, b) Greatest common divisor
mathLcm(a, b) Least common multiple
mathMean(arr) Average of numbers in array
mathMedian(arr) Middle value (sorted)
mathClamp(n, min, max) n if in range, else min/max
logos
use "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 word
strReverse(s) Reverse all characters
strIsPalindrome(s) true if reads same forwards/backwards
strIsEmpty(s) true if string is empty
strCount(s, sub) Count occurrences of sub in s
strPadStart(s, len, c) Pad s to len with c at start
strPadEnd(s, len, c) Pad s to len with c at end
logos
use "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 components
pathBase(p) Filename without directory
pathDir(p) Directory portion of path
pathExt(p) Extension including dot
pathWithoutExt(p) Path without extension
pathIsAbs(p) true if absolute path
pathExists(p) true if file/dir exists
logos
use "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") // true

std/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 table
datetimeAdd(dt, n, unit) Add n units (days/hours/etc)
datetimeSubtract(dt, n, unit) Subtract n units
datetimeDiff(d1, d2, unit) Difference in specified unit
datetimeFormat(dt, fmt) Format with Go time layout
datetimeIsAfter(d1, d2) true if d1 is later
logos
use "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 — white
logInfo(msg) Info level — green
logWarn(msg) Warning level — yellow
logError(msg) Error level — red
logos
use "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 started

std/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 string
isInt(val) Check if integer
isFloat(val) Check if float
isNumber(val) Check if int or float
isBool(val) Check if boolean
isArray(val) Check if array
isTable(val) Check if table
isCallable(val) Check if function
logos
use "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 mismatch
suite(name, fn) Group related assertions
summary() Print test results
test.lgs
use "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()