Skip to content

Language Basics

This page introduces the syntax you will use most often as a beginner.

Semicolons are optional.

print("Hello")
print("Hello again");

Single-line comments:

# This is a comment
print("Visible output") # Inline comment

Multiline comments:

#--
This block is ignored.
#--
print("done")

Use var to define variables.

var age = 25
var height = 1.75
var name = "Alice"

Reassign values when needed:

var score = 10
score = 12

Optional type annotation syntax:

var title = "Numo" :: String

Both print styles are accepted:

print "Hello"
print("Hello")

Stop execution with panic:

panic("Something went wrong")

Current core expression support includes:

  • Numbers
  • Strings
  • Booleans (true, false)
  • Variables
  • Function calls
  • + operator
  • Comparisons: ==, !=, <, <=, >, >=
var a = 10
var b = 20
print(a + b)
print("Hello, " + "Numo")

Define functions with func.

func greet(name) {
print("Hello, " + name)
}
func ping() {
print("pong")
}
greet("Numo")
ping()

Current implementation supports zero or one parameter.

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 = 0
while index < 3 {
print(index)
index = index + 1
}

Use loop when you want an infinite loop and will exit with break:

var index = 0
loop {
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"
}

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())

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.