Skip to main content

Getting Started

Every Nylon program needs a starting point, marked with the entrypoint keyword:

entrypoint main() = "hello world"

A program can define multiple entry points, but only one runs at startup:

entrypoint returnsString() = "The quick brown fox"
entrypoint returnsInt() = 12345

If a program has more than one entry point, mark the one that should run by default:

entrypoint.default main() = 1

Parameters and return values​

An entry point can take a single serializable input and return a single serializable output. This is how a Nylon program's result gets consumed by another program or tool:

# Since strings and integers are serializable, we can pass them as parameters.
entrypoint textLength(text: string) = text.length()

# Simple program that takes a person structure and determines if they can drink:
entrypoint canDrink(person: Person) = person.age >= 18
note

Entry points can only appear in executable programs, not in libraries.