Skip to content

Built-in Functions

Nubo includes a set of built-in functions and values that are available globally.

These functions cover console output, type inspection, conversion, runtime helpers, errors, environment variables, regex support, highlighting, and debugging.

Use print and println to write values to the console.

print("Hello, ")
println("Nubo")

Writes values without automatically adding a newline.

print("Loading...")
print("done")

Writes values and ends the line.

println("Hello")
println("Age:", 19)

Nubo provides helpers for inspecting values at runtime.

Returns the public type name of a value.

println(type("hello")) // string
println(type(123)) // int
println(type(true)) // bool

Returns a lower-level or internal type name.

println(_type([1, 2, 3]))

Returns the internal object ID for a value.

let user = "Martin"
println(_id(user))

Returns a detailed string representation of a value.

let values = [1, 2, 3]
println(inspect(values))

Returns the memory size of a value.

let text = "Nubo"
println(memsize(text))

Returns the underlying value of an object.

let value = valueof("hello")
println(value)

Returns the length of a supported value.

This is commonly used with strings, lists, and collection-like values.

println(len("Nubo")) // 4
println(len([1, 2, 3])) // 3

Concatenates values.

let name = concat("Nu", "bo")
println(name) // Nubo

Checks whether a value matches a type object.

println(typecheck(string, "hello")) // true
println(typecheck(int, "hello")) // false

Nubo includes helpers for working with references and copied values.

Returns a reference to a value.

let value = "Nubo"
let valueRef = ref(value)
println(valueRef)

Unwraps a referenced or wrapped value.

let value = "Nubo"
let valueRef = ref(value)
println(unwrap(valueRef))

Creates a clone of a value.

let list = [1, 2, 3]
let copied = clone(list)
println(copied)

Pauses execution for the given number of milliseconds.

println("Waiting...")
sleep(1000)
println("Done")

Exits the program with an optional exit code.

exit(0)

env(name: string, value: string? = nil) -> string?

Section titled “env(name: string, value: string? = nil) -> string?”

Reads or sets an environment variable.

When called with only a name, it returns the current value.

let home = env("HOME")
println(home)

When called with a name and value, it sets the environment variable.

env("APP_ENV", "development")
println(env("APP_ENV"))

If the variable does not exist, the function may return nil.

let missing = env("UNKNOWN_VARIABLE")
println(isNil(missing))

Stops execution with an error message.

panic("Something went wrong")

Checks whether a value is nil.

let value = nil
println(isNil(value)) // true

Nubo provides built-in conversion functions for common types.

Converts a value to a string.

println(string(123)) // "123"

Converts a value to an integer.

println(int("42"))
println(int(3.9))

Converts a value to a float.

println(float("3.14"))
println(float(10))

Converts a value to a boolean.

println(bool(1))
println(bool(""))

Converts a value to a byte.

let b = byte(65)
println(b)

Converts a value to a character.

let c = char(65)
println(c)

Converts a value to a list of bytes.

let data = bytes("Nubo")
println(data)

range is a built-in helper for creating numeric ranges.

It is useful for loops and repeated operations.

for i in range(0, 5) {
println(i)
}

Depending on the range API available in your version of Nubo, range may expose additional methods or forms.

for i in range(5) {
println(i)
}

highlight(code: string, mode: string = "console") -> string

Section titled “highlight(code: string, mode: string = "console") -> string”

Highlights source code and returns the highlighted output as a string.

The default mode is "console".

let code = "println(\"Hello\")"
println(highlight(code))

You can also pass a mode explicitly.

let code = "println(\"Hello\")"
println(highlight(code, "console"))

regex provides built-in regular expression support.

let re = regex("[a-z]+")
println(re)

The exact available methods depend on the regex object returned by the built-in regex() helper.

Common regex-style operations include matching, searching, and replacing text.

let pattern = regex("[0-9]+")
println(pattern)

Debug helper for inspecting runtime values.

let user = {
name: "Martin"
}
xdbg(user)

This function is intended for debugging and development.

The current Nubo version string.

println(__version__)
NameSignatureDescription
_id_id(obj: any) -> stringReturns the internal object ID.
printlnprintln(...)Prints values with a newline.
printprint(...)Prints values without a newline.
typetype(obj: any) -> stringReturns the public type name.
_type_type(obj: any) -> stringReturns the internal type name.
memsizememsize(obj: any) -> intReturns the memory size of a value.
inspectinspect(obj: any) -> stringReturns a detailed representation of a value.
sleepsleep(ms: int = 0) -> voidPauses execution.
refref(obj: any) -> anyReturns a reference to a value.
unwrapunwrap(obj: any) -> anyUnwraps a wrapped or referenced value.
cloneclone(obj: any) -> anyClones a value.
exitexit(code: int = 0) -> voidExits the program.
rangerangeRange helper for iteration.
envenv(name: string, value: string? = nil) -> string?Gets or sets environment variables.
concatconcat(...)Concatenates values.
lenlen(object: any) -> intReturns the length of a value.
typechecktypecheck(typ: type, value: any) -> boolChecks whether a value matches a type.
panicpanic(message: string)Stops execution with an error.
isNilisNil(obj: any) -> boolChecks whether a value is nil.
stringstring(obj: any) -> stringConverts a value to a string.
intint(obj: any) -> intConverts a value to an integer.
floatfloat(obj: any) -> floatConverts a value to a float.
boolbool(obj: any) -> boolConverts a value to a boolean.
bytebyte(obj: any) -> byteConverts a value to a byte.
charchar(obj: any) -> charConverts a value to a character.
bytesbytes(obj: any) -> []byteConverts a value to bytes.
valueofvalueof(obj: any) -> anyReturns the underlying value.
highlighthighlight(code: string, mode: string = "console") -> stringHighlights source code.
regexregex(...)Provides regular expression support.
xdbgxdbg(...)Debug helper.
__version__stringCurrent Nubo version.