Skip to content
Documentation

Standard library

Four built-in modules — Math, Text, File, and System — ship with the interpreter. Import them like any module (import Math); a same-named .lucc file you happen to have is ignored in favor of the built-in.

Shared rules for all functions listed here:

  • Strict types. Arguments are checked before the call; an int-expecting function rejects 7.0 and "7".
  • No implicit conversion and no none — passing none or a wrong type is an error (Cannot use 'none' as an argument to 'M.f').
  • Arity is exact. Calling with the wrong count is an error (Expected 2 arguments, found 3 style for fixed-arity functions; Expected at least 2 arguments for min/max).
  • Errors are ordinary runtime errors — a failed documented condition stops the run unless caught with try to (errors chapter).

Math — exact numeric helpers

FunctionSignatureReturnsBehavior
Math.sqrt(x)x int/dec ≥ 0decExact truncated square root, up to 10 decimal places, trailing zeros trimmed. Negative input → error (Math.sqrt of negative number).
Math.pow(base, exp)base int/dec, exp intdecExact exponentiation by squaring. exp must be int (Math.pow exponent must be int). pow(x, 0) is 1. Negative exponents divide, so pow(0, -1) → error (Division by zero).
Math.abs(x)x int/decsame type as inputAbsolute value, preserving int/dec.
Math.round(x)x int/decintHalf away from zero.
Math.floor(x)x int/decintRound toward negative infinity (mathematical).
Math.ceil(x)x int/decintRound toward positive infinity (mathematical).
Math.min(a, b, …)2+ int/decwinner's typeSmallest; all-int → int, any dec → dec.
Math.max(a, b, …)2+ int/decwinner's typeLargest; same mixing rule.

Verified console session:

import Math
print(Math.sqrt(25))
print(Math.pow(2, 10))
print(Math.round(2.5))
print(Math.abs(-3))
print(Math.max(1, 2.5))
5.0
1024.0
3
3
2.5

Text — string helpers

FunctionSignatureReturnsBehavior
Text.upper(s)s strstrUppercased copy.
Text.lower(s)s strstrLowercased copy.
Text.trim(s)s strstrCopy with edge whitespace removed.
Text.replace(s, old, new)all strstrAll occurrences of old replaced with new. An empty old inserts new at every character boundary (Text.replace("abc", "", "-") → -a-b-c-).
Text.split(s, sep)both strlist(str)Split on every occurrence of sep. An empty sep yields empty strings at both ends and between characters (Text.split("abc", "") → ["", "a", "b", "c", ""]).
Text.join(list, sep)list list(str), sep strstrElements joined with sep between them.

Verified console session (Text.split output shows collection quoting):

import Text
print(Text.upper("shout"))
print(Text.lower("CALM"))
print(Text.trim("  hi  ") + "|")
print(Text.replace("old new old", "old", "x"))
print(Text.split("a-b-c", "-"))
print(Text.join(["x", "y"], "+"))
SHOUT
calm
hi|
x new x
["a", "b", "c"]
x+y

File — files on disk

FunctionSignatureReturnsBehavior
File.read(path)path strstrWhole file contents; missing or unreadable → error (Could not read file '…').
File.write(path, content)both strnoneCreates or overwrites. Failure → error (Could not write file '…').
File.append(path, content)both strnoneCreates or appends. Failure → error.
File.exists(path)path strboolTrue for existing files and directories.
File.delete(path)path strnoneDeletes an existing file; deleting a missing path warns (File '…' does not exist) with no change; deleting a directory → error.

Paths are strings; relative paths resolve against the process working directory, and absolute paths are allowed. All failures except missing-path deletion are errors, so they pair naturally with try to in the tour chapter.

File.* grants a program the filesystem permissions of the user running luca: there is no sandbox, path allowlist, or size cap. Only run scripts you trust, and review File.write/append/delete calls before running code from elsewhere. luca check never touches the filesystem, so it is safe for inspection.

System — the host world

MemberKindReturnsBehavior
System.ospropertystrPlatform label (e.g. macos, linux, windows). Property form only — System.os() is an error.
System.archpropertystrArchitecture label (e.g. aarch64, x86_64).
System.args()functionlist(str)The full command line: the luca program, your script's path, then every extra word (luca script.lucc one two → […, script.lucc, one, two]).
System.env()functiondictEnvironment variables, dictionary keyed by name, sorted by name at call time.
System.exit(code)function—Terminate the run with code (32-bit range; outside → System.exit code out of range). Pending output flushes; finally blocks run; capture error never intercepts it (see the language reference).

Values for os/arch/environment depend on your machine; sample on one host: os=macos arch=aarch64.