Open Manual

Programs

A source file can be a script, a module, or both: use a script for a standalone program and a module when other files need exported names.

Prerequisites: the first-program guide or an installed Nytrix compiler. The tree below is schematic; these files are examples, not required repository paths.

project/
├── main.ny       # application entry point
└── mathx.ny      # reusable module

Script

Top-level statements run when a script is executed:

use core

def name = "Nytrix"
assert_eq("hello, " + name, "hello, Nytrix", "greeting")
print("hello, " + name)

Run it with ny hello.ny.

Module with an entry point

A module lists the names available to import. Put direct startup work in #main; importing the module does not run that block.

use core

module mathx(double)

fn double(int value) int {
   value * 2
}

#main {
   assert_eq(double(21), 42, "module entry")
}

The exact export and entry-point rules are in Units.

Imports

Import a module namespace or selected exported names. Aliases make the owner visible at each call site.

use core.os.net as net
use core.math.parse.data.json as json
use mathx (double)
use local:debug

Imports resolve before ordinary declarations. A missing module, export, or profile is a compile-time diagnostic.

For remote URL imports, append #sha256= and a 64-digit SHA-256 digest to pin the downloaded source. The compiler checks the digest on download and on every cache read. NYTRIX_REMOTE_RELOAD=1 fetches a fresh copy and replaces the cached file only after the download and digest check succeed.

Project layout

Keep reusable code in modules and application startup in one entry point. Use ny new <dir> for a starter project, then add modules around clear public interfaces. module name { export profile(...) } can publish a named profile when the same module needs multiple public surfaces.

Examples under etc/labs/ are complete programs.

Runnable projects

The checkout keeps runnable examples under etc/labs/ and focused runtime checks under etc/labs/tests/.

AreaProjects
Terminalconway.ny, matrix.ny, ant.ny
OSargs.ny, server.ny, ffi.ny, sound.ny
UIterm.ny, input.ny, monitor.ny, engine.ny, editor.ny

Run a project directly, build it as a native executable, or build the browser demo runner:

ny etc/labs/conway.ny
ny --output=build/conway etc/labs/conway.ny
./make web-demos

The generated build/web/demos/index.html is a compact WebGL-backed Wasm runner. Load a .wasm file from the page, or add browser-ready entries to etc/assets/website/wasm/demos.json.

Focused checks

Fixtures under etc/labs/tests/ exercise one language surface or runtime boundary:

TopicFixtures
ADTs and matchingadt.nshape, match.nshape
Concurrency and threadsconcurrency.nshape, thread.nshape
Comptimecomptime.nshape, table.nshape
Native boundaryffi.nshape, extern.nshape, asm.nshape
Ownership and safetyownership.nshape, safe.nshape, memory.nshape

Run a focused test by pattern:

ny test --pattern comptime
ny test --pattern ownership

Bench fixtures live under etc/labs/tests/bench/; run them through ny perf or ny test --pattern sieve. A single fixture run checks correctness, while comparative measurements require the flags and checksums in the performance guide.

Packages covers external source dependencies.

Next: