Language Basics
This page introduces the syntax you will use most often as a beginner.
Statements and semicolons
Section titled “Statements and semicolons”Semicolons are optional.
print("Hello")print("Hello again");Comments
Section titled “Comments”Single-line comments:
# This is a commentprint("Visible output") # Inline commentMultiline comments:
#--This block is ignored.#--print("done")Variables
Section titled “Variables”Use var to define variables.
var age = 25var height = 1.75var name = "Alice"Reassign values when needed:
var score = 10score = 12Optional type annotation syntax:
var title = "Numo" :: StringPrinting and panic
Section titled “Printing and panic”Both print styles are accepted:
print "Hello"print("Hello")Stop execution with panic:
panic("Something went wrong")Expressions
Section titled “Expressions”Current core expression support includes:
- Numbers
- Strings
- Booleans (
true,false) - Variables
- Function calls
+operator- Comparisons:
==,!=,<,<=,>,>=
var a = 10var b = 20print(a + b)print("Hello, " + "Numo")Functions
Section titled “Functions”Define functions with func.
func greet(name) { print("Hello, " + name)}
func ping() { print("pong")}
greet("Numo")ping()Current implementation supports zero or one parameter.
Control flow
Section titled “Control flow”Use if and else to branch on conditions:
if 3 < 5 { print("three is smaller")} else { print("unexpected")}Use while to repeat work:
var index = 0while index < 3 { print(index) index = index + 1}Use loop when you want an infinite loop and will exit with break:
var index = 0loop { print(index) index = index + 1
if index == 3 { break }}Use for when you want an initializer, condition, and update in one line:
for var i = 0; i < 5; i = i + 1 { if i == 2 { continue }
if i == 4 { break }
print(i)}Use return inside functions to send a value back:
func sign(value) { if value == 0 { return "zero" } return "non-zero"}Imports and modules
Section titled “Imports and modules”Built-in modules
Section titled “Built-in modules”Import built-in modules like this:
get math from "internal:math"print(math.pi())Try a small mixed example:
get math from "internal:math"get str from "internal:string"get sys from "internal:system"
var name = "numo"print("Language: " + str.upper(name))print("PI: " + math.pi())print("Platform: " + sys.platform())File-based modules
Section titled “File-based modules”You can also create your own modules by exporting functions from .numo files.
modules/print.numo:
export func coolPrint(string :: String) { print(string + ". Its cool right?")}main.numo:
get coolPrint from "modules/print.numo"
coolPrint("Bananas")Use export to make functions available for import. Import them with get ... from "path/to/file.numo". Both absolute and relative paths are supported.