Imports

Import statements allow you to use code from other modules in your Conjure programs. Imports must appear at the top of your source file, before any declarations.

Basic Imports

Use the import keyword followed by the module path in quotes. The last component of the path becomes the local namespace.

import "conjure/io"

// Now we can use io.print, io.println, etc.
io.println("Hello, world!")

Aliased Imports

Use as to give the imported module a different local name. This is useful when module names conflict or when you want a shorter name.

import "conjure/memory" as mem

var buffer = mem.alloc(1024)
defer mem.free(buffer)

Relative Imports

Use ./ to import modules relative to the current file’s directory.

import "./utils"
import "./game/player"

Standard Library Modules

Conjure provides several built-in modules in the standard library:

import "conjure/io"      // Input/output operations
import "conjure/memory"  // Memory allocation and management
import "conjure/math"    // Mathematical functions
import "conjure/string"  // String manipulation utilities

Multiple Imports

Import multiple modules by using separate import statements.

import "conjure/io" as io
import "conjure/math" as math
import "conjure/memory" as mem

Using Imported Symbols

Once imported, access the module’s public symbols using dot notation.

import "conjure/io" as io
import "conjure/math" as math

func main() {
	var angle f32 = math.PI / 4.0
	var result = math.sin(angle)
	io.println("sin(PI/4) = #{result}")
}

Module Visibility

Symbols in a module are public by default and can be accessed from importing code. Symbols prefixed with an underscore (_) are private to the module.

// In mymodule.cjr
var publicVar = 42       // accessible from importers
var _privateVar = 99     // only accessible within this module

func publicFunc() { }    // accessible from importers
func _privateFunc() { }  // only accessible within this module

Import Order

Import statements must appear:

  1. After any comments at the top of the file
  2. Before any variable, constant, function, or type declarations
// File header comments are allowed before imports

import "conjure/io" as io

// All imports must come before declarations
var globalCounter = 0

func main() {
	io.println("Counter: #{globalCounter}")
}