Standard Library

When you install EZ, it comes with a set of ready-to-use tools called the standard library (or “stdlib” for short). These are modules that handle common tasks so you don’t have to write everything from scratch.

Think of it like a toolbox that comes with your house — you didn’t have to buy the hammer and screwdriver separately, they’re just there when you need them.

What’s a Module?

A module is a collection of related functions grouped together. For example, all the math-related functions live in the @math module, and all the text-related functions live in the @strings module.

The @ symbol tells EZ “this is a built-in module” (as opposed to a file you created yourself).

How to Use a Module

Step 1: Import at the Top

Imports must go at the top of your file, before any other code:

import @math

do main() {
    // your code here
}

Note: Common functions like println, print, input, len, type_of, and others are builtins — always available without any import.

Step 2: Use with the Module Prefix

Once imported, use functions with the module name as a prefix:

math.sqrt(16.0)      // 4.0
println("Hi")        // prints "Hi" — builtin, no import needed

The math. prefix tells EZ which module the function comes from. This prevents confusion when two modules have functions with the same name.

Import Options

Import multiple modules on one line or separate lines:

import @math, @arrays
import @math
import @arrays

For beginners, use the prefix style — it makes it clear where each function comes from.

Click Here For Advanced Import Styles

Aliasing (Shorter Names)

Give a module a shorter name:

import s @strings
import m @math

do main() {
    s.to_upper("hello")    // instead of strings.to_upper()
    m.sqrt(16.0)           // instead of math.sqrt()
}

Using (Drop the Prefix)

The using keyword brings a module’s contents into scope, so you can call functions without the prefix:

import @math
using math

do main() {
    mut result = sqrt(pow(3.0, 2.0) + pow(4.0, 2.0))
    println(result)  // 5.0
}

Import and Use (Combined)

Combines import and using in one statement, making the module available without a prefix:

import and use @arrays

do main() {
    mut nums [int] = {1, 2, 3}
    append(nums, 4)  // No arrays. prefix needed
}

When to Use What

StyleSyntaxBest For
Basicimport @mathMost code — prefix makes origin clear
Aliasimport m @mathLong module names you use frequently
Usingusing mathWhen you heavily use one module
Combinedimport and use @arraysLess typing, small scripts

Available Modules

EZ includes twenty-six built-in modules:

ModuleWhat it’s for
@mathMath operations — square roots, powers, logarithms
@randomRandom generation — numbers, choices, shuffling
@arraysWorking with lists — sorting, filtering, finding items
@stringsWorking with text — uppercase, splitting, trimming
@mapsKey-value storage — like a dictionary or phonebook
@timeDates and time — current time, formatting, timing
@bytesBinary data — encoding, decoding, byte manipulation
@ioFile system — reading, writing, paths, directories
@osOperating system — environment, platform detection, commands
@jsonJSON parsing — encoding, decoding, validation
@httpHTTP client — web requests, URL encoding, status codes
@binaryBinary encoding — numeric type serialization with endianness control
@uuidUUID generation — create and validate unique identifiers
@encodingData encoding — Base64, hex, and URL encoding/decoding
@cryptoCryptography — hashing (SHA-256, MD5) and secure random
@regexRegular expressions — matching, finding, replacing patterns
@csvCSV — parsing, generating, reading, and writing CSV data
@sqliteDatabase — SQLite database access for persistent storage
@serverHTTP server — routing, response helpers, and serving
@fmtFormatting — printf-style formatting, padding, number display
@netNetworking — TCP sockets and DNS resolution
@threadsThreading — spawn and join threads
@syncSynchronization — mutexes for thread-safe access
@channelsChannels — message passing between threads
@memMemory — arena-based memory allocation
@atomicAtomics — lock-free atomic operations and spinlocks

Quick Example

Here’s a small program that uses two different modules:

import @math
import @strings

do main() {
    // Builtins — no import needed
    println("Welcome!")

    // @math for calculations
    mut radius = 5.0
    mut area = math.PI * math.pow(radius, 2.0)
    println("Circle area:", area)

    // @strings for text manipulation
    mut name = strings.trim("  alice  ")
    mut upper = strings.to_upper(name)
    println("Hello,", upper)  // "ALICE"
}

Tips for Beginners

You don’t need to memorize everything — Bookmark this page. When you need to do something with arrays, check the @arrays page. Need to format a date? Check @time. The docs are here for reference.

Import only what you need — If your program only prints text, you don’t need any imports at all (println is a builtin). Only import modules when you need their specific functions.

Next Steps

Pick a module and explore what it can do:

  • Builtins — Always available, no import needed
  • @math — For calculations and logarithms
  • @random — For random numbers and shuffling
  • @arrays — For working with lists of things
  • @strings — For manipulating text
  • @maps — For key-value data
  • @time — For dates, times, and timing
  • @bytes — For binary data and encoding
  • @io — For file and directory operations
  • @os — For system info, environment, and commands
  • @json — For JSON encoding, decoding, and validation
  • @http — For making web requests and working with URLs
  • @binary — For binary encoding and decoding with endianness
  • @uuid — For generating and validating UUIDs
  • @encoding — For Base64, hex, and URL encoding
  • @crypto — For cryptographic hashing and secure random
  • @regex — For regular expression operations
  • @csv — For CSV parsing and file operations
  • @sqlite — For SQLite database operations
  • @server — For building HTTP servers with routing
  • @fmt — For formatted output and string formatting
  • @net — For TCP sockets and DNS
  • @threads — For thread lifecycle management
  • @sync — For mutexes and synchronization
  • @channels — For message passing between threads
  • @mem — For arena-based memory management
  • @atomic — For lock-free atomic operations