Onyx Examples

This page provides several simple examples of Onyx code, showing how to do common things with the standard library.

Standard Input

input io reader conv
This example reads a single line of input from standard input, splits it in half on the first space using string.bisect, converts both parts to integers using conv.parse, then prints the results using printf for formatted printing.

File Operations

io reader os file
This example shows various ways of reading and writing to a file. The core idea behind files in Onyx is that they extend the io.Stream structure, so you can use the core.io package to interact with them.

Fibonacci Sequence

loops iterators
This example shows three different ways to do the same thing: compute Fibonacci numbers.

Want to learn more?

Visit the docs!

You can learn more details about Onyx by visiting the docs! There is more examples, a reference manual for the language, and documentation for the standard library.

© 2020-2024 Brendan Hansen