builtinsBuilt-in functions available in every Hew program.
These functions are always in scope — no import is needed.
They cover I/O, assertions, math, string operations, and
program control flow.
printlnPrint a value followed by a newline.
Accepts any type that implements Display.
println(42);
println("hello");
println(true);
printPrint a value without a trailing newline.
print("Enter name: ");
assertAssert that a condition is true. Panics if condition is false.
assert(x > 0);
assert_eqAssert that two values are equal. Panics with a diff if they differ.
Both arguments must be the same type.
assert_eq(add(1, 2), 3);
assert_neAssert that two values are not equal. Panics if they are the same.
Both arguments must be the same type.
assert_ne(a, b);
absReturns the absolute value of an integer.
let x = abs(-5); // 5
sqrtReturns the square root of a floating-point number.
let r = sqrt(9.0); // 3.0
minReturns the smaller of two integers.
maxReturns the larger of two integers.
to_floatConvert an integer to a floating-point number.
let f = to_float(42); // 42.0
string_concatConcatenate two strings, returning a new string.
let full = string_concat("hello ", "world");
string_lengthReturns the byte length of a string.
to_stringConvert any value to its string representation.
let s = to_string(42); // "42"
lenReturns the length of a collection or string.
string_char_atReturns the character (as a char) at the given byte index.
string_equalsTest whether two strings are equal.
string_from_intConvert an integer to a string.
let s = string_from_int(42); // "42"
string_containsTest whether haystack contains needle.
string_starts_withTest whether a string starts with the given prefix.
substringExtract a substring by byte indices [start, end).
let s = substring("hello", 0, 3); // "hel"
string_trimStrip leading and trailing whitespace.
string_to_intParse a string as an integer. Returns 0 on failure.
string_findFind the first occurrence of needle in haystack.
Returns the byte offset, or -1 if not found.
read_fileRead the entire contents of a file as a string.
write_fileWrite a string to a file, creating or overwriting it.
sleep_msPause execution for the given number of milliseconds.
sleepPause execution for the given number of seconds.
stopStop an actor gracefully.
exitTerminate the program with the given exit code.
This function never returns.
panicTerminate the program with an error message.
This function never returns.
panic("something went wrong");