Attach / Modules

Astra lets you split your code across multiple .astra files and load them with attach. Functions defined in the attached file become available in your program instantly — no build steps, no exports.

SyntaxWhat it does
attach "file.astra"Load file, functions available directly by name
attach "file.astra" as xLoad file, functions available as x.fnName()

Basic attach

Use attach "filename.astra" to load another file. All functions defined in that file can be called directly — no prefix needed.

utils.astra
#f add(a, b) write a + b #ef #f mul(a, b) write a * b #ef
main.astra
attach "utils.astra" add(10, 20) \\ 30 mul(20, 30) \\ 600
💡 All functions from the attached file are available directly — call add(), mul() without any prefix.

attach as — Alias

If two files define the same function name, they will conflict. Use attach "file.astra" as name to give a file a namespace — then call its functions as name.function().

utils.astra
#f add(a, b) write a + b #ef #f mul(a, b) write a * b #ef
mathlib.astra
#f add(a, b) write a + b #ef
main.astra
attach "utils.astra" as u attach "mathlib.astra" as m u.add(10, 20) \\ 30 u.mul(20, 30) \\ 600 m.add(11, 22) \\ 33
⚠️ If two files define the same function name, an alias is required — otherwise there will be a conflict.

Multiple Modules

You can attach as many files as you need — with or without an alias.

main.astra
attach "utils.astra" attach "mathlib.astra" as m \\ from utils.astra — directly add(10, 20) mul(5, 6) \\ from mathlib.astra — with alias m.add(11, 22)

Writing a Module

Just define functions in any .astrafile — that's it, it's a module. No special syntax, no exports needed.

Example — strings.astra

strings.astra
#f greet(name) write "Hello, " + name + "!" #ef #f shout(msg) add text write upper(msg) #ef
main.astra
attach "strings.astra" as s s.greet("Vijay") \\ Hello, Vijay! s.shout("astra") \\ ASTRA

Example — math utils

mathutils.astra
#f square(n) return n * n #ef #f cube(n) return n * n * n #ef #f isEven(n) if n % 2 == 0 return true ; return false #ef
main.astra
attach "mathutils.astra" as mu write mu.square(5) \\ 25 write mu.cube(3) \\ 27 write mu.isEven(4) \\ TRUE write mu.isEven(7) \\ FALSE

Common Patterns

Shared constants file

config.astra
\\ shared constants APP_NAME = "MyApp" VERSION = "1.0.0" MAX_SIZE = 100
main.astra
attach "config.astra" write APP_NAME \\ MyApp write VERSION \\ 1.0.0

Split by feature

main.astra
attach "auth.astra" as auth attach "db.astra" as db attach "utils.astra" \\ clean, organized code auth.login("admin", "pass") db.save("users", data) log("App started")
ℹ️ Attached files can themselves use attach — nested modules are supported. File paths are resolved relative to the location of the .astra file.