Neon
← Back to ContainersNext: Conditional blocks →

Functions (Usage)

Functions are reusable blocks of code that perform actions and return results. Neon has built-in functions and user-defined functions.

Calling Built-in Functions

Neon provides many built-in functions. Call them with parentheses:

# Math
abs(-5)      # → 5
sqrt(16)     # → 4.0
sin(0)       # → 0.0 (radians)
cos(0)       # → 1.0
floor(3.7)   # → 3.0
ceil(3.2)    # → 4.0
round(3.1415, 2)  # → 3.14

# String operations
len("hello")          # → 5
sub("hello", 1, 4)   # → "ell" (from index 1 to 3)
replace("hello", "l", "x")  # → "hexxo"

# List operations
len([1, 2, 3])       # → 3
reverse([1, 2, 3])   # → [3, 2, 1]

# Type conversion
int("123")           # → 123
str(42)              # → "42"
nbr("3.14")          # → 3.14 (Real)

# Randomness
randint(1, 10)       # → Random integer between 1 and 9

# Time
time()               # → Seconds since epoch (system-dependent)

# I/O
print("Hello")       # Prints "Hello" with a newline
output("No newline") # Prints without a newline
input("Enter name: ") # Waits for user input

# System
exit()               # Exits the interpreter
gc()                 # Runs garbage collection
help(print)          # Shows help for the print function

← Back to ContainersNext: Conditional blocks →