N

Nanyx

Documentation

Getting Started

Welcome to Nanyx! This guide will help you get up and running with the language.

Prerequisites

  • .NET 9.0 or later (for the compiler)
  • (Optional) VS Code for syntax highlighting

Installation

Clone the repository:

git clone https://github.com/Richiban/nyx.git
cd nyx

Build the compiler:

cd compiler
dotnet build Nyx.Compiler.sln

Run tests to verify the installation:

dotnet test Nyx.Compiler.sln

Your First Nanyx Program

Create a file hello.nyx:

module Hello

def message = "Hello, Nanyx!"

def main = {
  message \dbg
}

main()

Compile and type-check it:

dotnet run --project compiler/Nyx.Compiler.Cli/NyxCompiler.Cli.fsproj hello.nyx

Basic Concepts

Value Definitions

Define values with def:

def pi = 3.14159
def greeting = "Hello"
def count = 42
def isActive = true

Functions

Functions are first-class values:

-- Named function with type annotation
def double: int -> int = { x -> x * 2 }

-- Multi-parameter function (takes a record)
def add: (int, int) -> int = { x, y -> x + y }

Pipelines

Chain transformations with the \ operator:

42 \double \dbg  -- prints 84

"hello world"
  \split(" ")
  \map { .toUpperCase() }
  \join("-")
  \dbg  -- prints "HELLO-WORLD"

Pattern Matching

Match on values with exhaustive checking:

def classify: int -> string = { x ->
  match x
    | 0 -> "zero"
    | 1 -> "one"
    | n if n < 0 -> "negative"
    | _ -> "other"
}

What to Try Next

  • Create a record and pattern match on it
  • Write a function that uses the pipeline operator
  • Explore the examples in the examples/ directory
  • Read through the language features in the documentation