Built-in Function Reference

Complete reference for every built-in function in Strada, organized by namespace.

Namespaces
core:: — system & libc. Use this in new code.
math:: — math.
async:: — threading, channels, mutexes, futures.
c:: — low-level memory & FFI.
Bare built-ins (no namespace) match Perl one-to-one in most cases.
sys:: is the legacy alias. It still compiles, but new code should use core::. The compiler normalizes core:: to sys:: internally for both forms to resolve to the same C runtime.

Quick Index

math:: — Math functions

All math functions take and return scalars. Most are libm wrappers.

FunctionSignatureDescription
math::abs(x)num→numAbsolute value.
math::acos(x)num→numArc cosine, result in [0, π].
math::asin(x)num→numArc sine, result in [-π/2, π/2].
math::atan(x)num→numArc tangent.
math::atan2(y, x)num,num→numArc tangent of y/x, using both signs to pick the quadrant.
math::cbrt(x)num→numCube root.
math::ceil(x)num→numSmallest integer ≥ x.
math::copysign(x, y)num,num→numx with sign of y.
math::cos(x)num→numCosine (radians).
math::cosh(x)num→numHyperbolic cosine.
math::exp(x)num→numex.
math::fabs(x)num→numAbsolute value (alias).
math::floor(x)num→numLargest integer ≤ x.
math::fmax(x, y)num,num→numMax.
math::fmin(x, y)num,num→numMin.
math::fmod(x, y)num,num→numFloating-point remainder.
math::frexp(x)num→array[mantissa, exponent] s.t. x = m×2e.
math::hypot(x, y)num,num→numsqrt(x² + y²) without overflow.
math::isfinite(x)num→int1 if finite.
math::isinf(x)num→int1 if infinity.
math::isnan(x)num→int1 if NaN.
math::ldexp(x, e)num,int→numx × 2e.
math::log(x)num→numNatural log.
math::log10(x)num→numBase-10 logarithm.
math::modf(x)num→array[integer part, fractional part].
math::pow(x, y)num,num→numxy.
math::rand()→numRandom in [0, 1).
math::remainder(x, y)num,num→numIEEE 754 remainder.
math::round(x)num→numRound to nearest (away from zero on halfway).
math::scalbn(x, e)num,int→numx × 2e (integer exponent).
math::sin(x)num→numSine (radians).
math::sinh(x)num→numHyperbolic sine.
math::sqrt(x)num→numSquare root.
math::tan(x)num→numTangent (radians).
math::tanh(x)num→numHyperbolic tangent.
math::trunc(x)num→numTruncate towards zero.

async:: — Async, Threading, IPC

Strada uses a thread-pool backend (default 4 workers).

Futures

FunctionDescription
async::all(@futures)Wait for all; returns ordered result array.
async::race(@futures)Wait for first; returns its value.
async::timeout(future, ms)Wait up to ms ms; undef on timeout.
async::cancel(future)Request cancellation.
async::is_cancelled(future)1 if cancellation requested.
async::is_done(future)1 if completed.
async::pool_init(n)Initialize thread pool with n workers.
async::pool_shutdown()Drain and shutdown pool.

Channels

FunctionDescription
async::channel(cap)Buffered channel; cap=0 for unbuffered.
async::send(ch, v)Send (blocks if full).
async::recv(ch)Receive (blocks if empty).
async::try_send(ch, v)Non-blocking send.
async::try_recv(ch)Non-blocking receive.
async::close(ch)Close channel.
async::is_closed(ch)1 if closed.
async::len(ch)Current item count.

Mutexes

FunctionDescription
async::mutex()New mutex.
async::lock(mtx)Acquire (blocks).
async::try_lock(mtx)Non-blocking acquire.
async::unlock(mtx)Release.
async::mutex_destroy(mtx)Free.

Atomics

FunctionDescription
async::atomic(v)Create atomic int.
async::atomic_load(at)Read.
async::atomic_store(at, v)Write.
async::atomic_add(at, n)Add; returns previous.
async::atomic_sub(at, n)Subtract; returns previous.
async::atomic_inc(at)+1; returns previous.
async::atomic_dec(at)-1; returns previous.
async::atomic_cas(at, exp, new)Compare-and-swap.

c:: — Low-level memory and FFI

FunctionDescription
c::alloc(size)malloc(size).
c::realloc(ptr, size)realloc.
c::free(ptr)free().
c::null()NULL pointer.
c::is_null(ptr)1 if NULL.
c::memcpy(dst, src, n)Copy n bytes.
c::memset(ptr, b, n)Fill n bytes.
c::ptr_add(ptr, off)Pointer arithmetic.
c::ptr_to_str(ptr)NUL-term'd C str → Strada str.
c::ptr_to_str_n(ptr, n)n bytes from ptr.
c::str_to_ptr(s)Pointer to string's bytes.
c::read_float(ptr)Read float at ptr.
c::read_double(ptr)Read double.
c::read_ptr(ptr)Dereference pointer-to-pointer.
c::write_float(ptr, v)Write float.
c::write_double(ptr, v)Write double.
c::write_ptr(ptr, v)Write pointer.
c::sizeof_int()sizeof(int).
c::sizeof_long()sizeof(long).
c::sizeof_ptr()sizeof(void*).
c::sizeof_size_t()sizeof(size_t).

core:: — System interface

Use core:: in user code. sys:: is a legacy alias that still works for backward compatibility (the compiler normalizes core:: to sys:: internally), but new code should write core::.

Process control

FunctionSignatureDescription
core::fork()→intfork(2); returns child pid in parent, 0 in child, -1 on error.
core::exec(cmd)str→intexeclp; replaces current process.
core::exec_argv(@argv)array→intexecvp with argument list.
core::system(cmd)str→intShell out via /bin/sh -c; returns exit status.
core::system_argv(@argv)array→intsystem with argv (no shell).
core::wait()→intwait(2); returns child pid; updates $?.
core::waitpid(pid, flags)int,int→intwaitpid(2).
core::kill(sig, pid)str/int,int→intSend signal. Sig may be name ("USR1") or number.
core::killpg(pgid, sig)int,int→intkillpg(2).
core::exit(code)int→voidRun END blocks then exit(code).
core::_exit(code)int→void_exit(2); skips END blocks.
core::exit_status(status)int→intWEXITSTATUS-equivalent extraction.
core::getpid()→intCurrent process id.
core::getppid()→intParent process id.
core::getpgid(pid)int→intProcess group id.
core::getpgrp()→intProcess group id of current process.
core::setpgid(pid, pgid)int,int→intSet process group.
core::setpgrp()→intMake current process a process-group leader.
core::setsid()→intCreate new session.
core::getsid(pid)int→intSession id.
core::nice(inc)int→intAdjust scheduling priority.
core::getpriority(which, who)int,int→intgetpriority(2).
core::setpriority(which, who, prio)int,int,int→intsetpriority(2).
core::pause()→intpause(2); sleep until signal.
core::alarm(sec)int→intalarm(2).
core::umask(mask)int→intumask(2).
core::chroot(dir)str→intchroot(2).
core::chdir(dir)str→intchdir(2).
core::getcwd()→strgetcwd(3).
core::times()→array[user, system, cuser, csystem] CPU times.
core::getrlimit(resource)int→array[soft, hard] limits.
core::setrlimit(resource, soft, hard)int,int,int→intsetrlimit(2).
core::getrusage(who)int→arraygetrusage(2).

User / group

FunctionDescription
core::getuid()Real user id.
core::geteuid()Effective user id.
core::setuid(uid)setuid(2).
core::seteuid(uid)seteuid(2).
core::setreuid(real, eff)setreuid(2).
core::getgid()Real group id.
core::getegid()Effective group id.
core::setgid(gid)setgid(2).
core::setegid(gid)setegid(2).
core::setregid(real, eff)setregid(2).
core::getgroups()Supplementary groups.
core::getpwuid(uid)Password entry by uid.
core::getpwnam(name)Password entry by name.
core::getgrgid(gid)Group entry by gid.
core::getgrnam(name)Group entry by name.
core::getlogin()Login name.

File I/O

FunctionDescription
core::open(path, mode)Open file; mode ∈ {"r","w","a","rb","<",">",">>","+>"}.
core::close(fh)Close filehandle.
core::open_fd(fd, mode)fdopen(3); wrap an fd as filehandle.
core::open_str(ref)In-memory open over a scalar ref.
core::fdopen_read(fd)Open fd for reading.
core::fdopen_write(fd)Open fd for writing.
core::close_fd(fd)close(2).
core::readline(fh)Read one line (or undef at EOF).
core::read_fd(fd, n)read(2) up to n bytes.
core::read_all_fd(fd)Read until EOF.
core::read_byte(fh)Read one byte (-1 on EOF).
core::write_fd(fd, data)write(2).
core::seek(fh, offset, whence)fseek; whence ∈ {0,1,2}.
core::tell(fh)ftell(3).
core::eof(fh)feof(3).
core::flush(fh)fflush(3).
core::autoflush(fh, on)setvbuf to _IONBF when on, else _IOFBF. Matches perl $|=1.
core::rewind(fh)rewind(3).
core::clearerr(fh)clearerr(3).
core::ferror(fh)ferror(3).
core::fileno(fh)Underlying fd.
core::fread(fh, len)Read len bytes from fh.
core::fwrite(fh, data)Write data to fh.
core::fgetc(fh)Read one char (-1 on EOF).
core::fputc(c, fh)Write one char.
core::fgets(fh, max)Read up to max bytes or newline.
core::fputs(s, fh)Write string to fh.
core::dup(fd)dup(2).
core::pipe()Returns [read_fd, write_fd].
core::popen(cmd, mode)popen(3).
core::pclose(fh)pclose(3).
core::tmpfile()tmpfile(3) — auto-deleted filehandle.
core::mkstemp(template)mkstemp(3); returns [fd, path].
core::mkdtemp(template)mkdtemp(3); returns path.
core::slurp(path)Read entire file into string.
core::slurp_fd(fd)Slurp from fd.
core::slurp_fh(fh)Slurp from filehandle.
core::spew(path, data)Write entire string to file (truncate).
core::spew_fd(fd, data)Write to fd.
core::spew_fh(fh, data)Write to filehandle.
core::str_from_fh(fh)Slurp filehandle to string.
core::qx(cmd)Capture command output (shell).
core::flock(fh, op)flock(2); op ∈ {LOCK_SH=1, LOCK_EX=2, LOCK_UN=8, LOCK_NB=4}.

Filesystem

FunctionDescription
core::file_exists(path)Existence (any type).
core::is_file(path)Regular file?
core::is_dir(path)Directory?
core::is_symlink(path)Symbolic link?
core::is_readable(path)Readable by current user?
core::is_writable(path)Writable?
core::is_executable(path)Executable?
core::is_zero_size(path)Zero-byte file?
core::dir_exists(path)Directory existence (alias for is_dir).
core::file_size(path)Bytes; -1 on error.
core::file_mtime(path)Modification time (epoch).
core::file_ext(path)Filename extension (no leading ".").
core::basename(path)Basename (last component).
core::dirname(path)Directory part.
core::path_join(@parts)Join with platform separator.
core::realpath(path)Resolve symlinks; absolute path.
core::readlink(path)readlink(2).
core::symlink(target, link)symlink(2).
core::link(src, dst)link(2) (hard link).
core::unlink(path)Remove a file.
core::rename(old, new)rename(2).
core::mkdir(path, mode)mkdir(2).
core::rmdir(path)rmdir(2).
core::chmod(mode, path)chmod(2).
core::fchmod(fh, mode)fchmod(2).
core::chown(uid, gid, path)chown(2).
core::fchown(fh, uid, gid)fchown(2).
core::lchown(uid, gid, path)lchown(2).
core::access(path, mode)access(2).
core::truncate(path, len)truncate(2).
core::ftruncate(fh, len)ftruncate(2).
core::stat(path)stat(2); 13-element list.
core::lstat(path)lstat(2).
core::statvfs(path)statvfs(3).
core::fstatvfs(fh)fstatvfs(3).
core::utime(atime, mtime, @paths)utime(2).
core::utimes(atime, mtime, path)utimes(2).
core::glob(pattern)Filename globbing.
core::fnmatch(pattern, name)fnmatch(3).
core::opendir(path)Open directory.
core::readdir(dh)All entries.
core::readdir_next(dh)One entry (undef when done).
core::readdir_full(dh)Entries with type info.
core::closedir(dh)Close directory.

Time

FunctionDescription
core::time()Seconds since epoch.
core::hires_time()Sub-second seconds since epoch.
core::gettimeofday()[sec, usec].
core::tv_interval(t1, t2)Difference in seconds.
core::nanosleep(sec)Sleep with sub-second precision.
core::sleep(sec)Whole-second sleep.
core::usleep(usec)Microsecond sleep.
core::localtime(epoch)Local time 9-tuple.
core::gmtime(epoch)UTC time 9-tuple.
core::mktime(@parts)Inverse of localtime.
core::strftime(fmt, @parts)Format time.
core::ctime(epoch)"Day Mon DD HH:MM:SS YYYY".
core::difftime(t2, t1)t2 − t1 in seconds.
core::clock()CPU clock ticks.
core::clock_gettime(clk)clock_gettime(2).
core::clock_getres(clk)Resolution.

Network / sockets

FunctionDescription
core::socket_client(host, port)TCP connect.
core::socket_server(host, port)TCP listen socket.
core::socket_server_backlog(host, port, backlog)TCP listen with explicit backlog.
core::socket_accept(srv)Accept a connection.
core::socket_send(sock, data)Send bytes.
core::socket_recv(sock, n)Receive up to n bytes.
core::socket_close(sock)Close.
core::socket_flush(sock)Flush write buffer.
core::socket_select(@socks)Indexes of ready sockets.
core::socket_fd(sock)Underlying fd.
core::socket_set_nonblocking(sock)Set O_NONBLOCK.
core::shutdown(sock, how)shutdown(2); how ∈ {0,1,2}.
core::getsockname(sock)Local [addr, port].
core::getpeername(sock)Remote [addr, port].
core::getsockopt(sock, level, opt)getsockopt(2).
core::setsockopt(sock, level, opt, val)setsockopt(2).
core::udp_socket()New UDP socket.
core::udp_bind(sock, host, port)Bind UDP socket.
core::udp_server(host, port)UDP socket + bind.
core::udp_sendto(sock, data, host, port)sendto.
core::udp_recvfrom(sock, max)[data, addr, port].
core::gethostname()gethostname(3).
core::gethostbyname(host)First IP for hostname.
core::gethostbyname_all(host)All IPs.
core::getaddrinfo(host, port)getaddrinfo(3).
core::inet_addr(ip)"1.2.3.4" → 32-bit int.
core::inet_ntoa(addr)int → "1.2.3.4".
core::inet_pton(af, str)Address presentation→binary.
core::inet_ntop(af, bin)Binary→presentation.
core::htonl(n)Host → network long.
core::ntohl(n)Network → host long.
core::htons(n)Host → network short.
core::ntohs(n)Network → host short.

Process I/O & terminal

FunctionDescription
core::ioctl(fd, req, arg)ioctl(2).
core::fcntl(fd, cmd, arg)fcntl(2).
core::poll(@fds, timeout)poll(2).
core::select_fds(rfds, wfds, efds, timeout)select(2).
core::isatty(fd)isatty(3).
core::ttyname(fd)ttyname(3).
core::term_rows()Terminal height.
core::term_cols()Terminal width.
core::term_enable_raw()Put terminal into raw mode.
core::term_disable_raw()Restore terminal mode.
core::tcgetattr(fd)Read terminal attributes.
core::tcsetattr(fd, attrs)Write terminal attributes.
core::tcdrain(fd)tcdrain(2).
core::tcflush(fd, q)tcflush(2).
core::cfgetispeed(attrs)Input speed.
core::cfgetospeed(attrs)Output speed.
core::cfsetispeed(attrs, speed)Set input speed.
core::cfsetospeed(attrs, speed)Set output speed.
core::serial_open(path)Open serial port.

Signals

FunctionDescription
core::signal(name, handler)Install handler. handler can be a code ref, "IGNORE", or "DEFAULT".
core::raise(sig)raise(3).
core::sigprocmask(how, set)sigprocmask(2).

Environment

FunctionDescription
core::getenv(name)Get env variable (or undef).
core::setenv(name, val)setenv(3).
core::unsetenv(name)unsetenv(3).
core::argv()Command-line args.
core::getprocname()argv[0].
core::setprocname(name)Set process name.
core::getproctitle()Full process title.
core::setproctitle(title)Override process title.

Memory & dynamic loader

FunctionDescription
core::mmap(addr, len, prot, flags, fd, off)mmap(2).
core::munmap(addr, len)munmap(2).
core::mlock(addr, len)mlock(2).
core::munlock(addr, len)munlock(2).
core::calloc(n, sz)calloc(3).
core::realloc(ptr, sz)realloc(3).
core::free(ptr)free(3).
core::dl_open(path)dlopen(3).
core::dl_close(handle)dlclose.
core::dl_sym(handle, name)dlsym.
core::dl_error()dlerror.
core::dl_call_void(sym, @args)Call void(...).
core::dl_call_int(sym, @args)Call int(...).
core::dl_call_num(sym, @args)Call double(...).
core::dl_call_str(sym, @args)Returns char*.
core::dl_call_void_sv(sym, @args)Pass StradaValue* args.
core::dl_call_int_sv(sym, @args)StradaValue args, int return.
core::dl_call_str_sv(sym, @args)StradaValue args, str return.
core::dl_call_sv(sym, @args)StradaValue args + return.
core::dl_call_export_info(sym)Read __strada_export_info.
core::dl_call_version(sym)Module version string.

Strings & encoding

Strings are UTF-8 character orientedlength, substr, index, reverse count Unicode codepoints. For byte-level access (binary protocols, file formats), use the core::byte_* family below.

FunctionDescription
core::pack(fmt, @vals)Binary pack. Codes: c C s S l L i I q Q n v N V f d a A Z H h B b x X w u U (w=BER, u=uuencode, U=UTF-8 codepoint); </> endian, * = all.
core::unpack(fmt, data)Binary unpack (same format codes).
core::vec_get(s, off, bits)Perl vec() rvalue: read a bits-wide field.
core::vec_set(s, off, bits, val)Perl vec() lvalue: set field, growing s.
core::ord_byte(s)First byte ordinal (0–255).
core::byte_length(s)Length in bytes (vs length = codepoints).
core::byte_substr(s, off, len)Byte-offset substring.
core::get_byte(s, pos)Byte at position (0–255).
core::set_byte(s, pos, val)Return s with byte replaced.
utf8::is_utf8(s) / utf8::valid(s)1 if string is valid UTF-8.
utf8::encode(s) / utf8::decode(s)No-op (strings are already byte-encoded and char-oriented).
utf8::upgrade(s) / utf8::downgrade(s)No-op (same).
core::read_byte(fh)Read one byte.
core::hex(s)Parse hex string.
core::random_bytes(n)Cryptographic random bytes.
core::random_bytes_hex(n)Random bytes as hex.
core::strerror(errno)Errno → message.
core::strtod(s)strtod(3).
core::strtol(s, base)strtol(3).
core::atof(s)atof(3).
core::atoi(s)atoi(3).
core::quotemeta(s)Escape regex metacharacters.

Errors & introspection

FunctionDescription
core::errno()Current errno.
core::caller(level)Hash with function/file/line.
core::stack_trace()Formatted call stack.
core::wantarray()1 in list context, 0 in scalar, undef in void.
core::wanthash()1 if caller expects a hash.
core::wantscalar()1 in scalar context.
core::set_recursion_limit(n)Set max sub recursion depth.
core::get_recursion_limit()Current limit.
core::isweak(ref)1 if a weak reference.
core::weaken(ref)Make a weak reference.
core::release(ref)Force-free a reference.

Globals & package storage

FunctionDescription
core::global_get(name)Read package-scoped global.
core::global_set(name, val)Write global.
core::global_exists(name)Existence check.
core::global_delete(name)Remove and return.
core::global_keys()All package-global keys.

Profiling & tuning

FunctionDescription
core::full_profile_start(path)Begin line-level profiling.
core::full_profile_stop()Stop profiling.
core::memprof_enable()Enable allocation tracking.
core::memprof_disable()Disable.
core::memprof_report()Report by type.
core::memprof_reset()Zero counters.
core::hash_default_capacity(n)Default capacity for new hashes.
core::array_default_capacity(n)Default capacity for new arrays.

C struct interop

FunctionDescription
core::cstruct_new(layout)Allocate a struct described by layout.
core::cstruct_get_int(cs, field)Read int field.
core::cstruct_get_double(cs, field)Read double field.
core::cstruct_get_string(cs, field)Read string field.
core::cstruct_set_int(cs, field, v)Write int field.
core::cstruct_set_double(cs, field, v)Write double field.
core::cstruct_set_string(cs, field, v)Write string field.
core::cstruct_ptr(cs)Raw pointer to the struct.
core::int_ptr(v)Pointer to an int holding v.
core::num_ptr(v)Pointer to a double holding v.
core::str_ptr(v)Pointer to a C string.
core::ptr_deref_int(ptr)Read int through pointer.
core::ptr_deref_num(ptr)Read num through pointer.
core::ptr_deref_str(ptr)Read C string through pointer.
core::ptr_set_int(ptr, v)Write int through pointer.
core::ptr_set_num(ptr, v)Write num through pointer.

utf8:: — Unicode / UTF-8

UTF-8 introspection plus the full UAX#15 normalization forms. Tables are bundled (Unicode 15.0.0); Hangul is handled algorithmically.

FunctionDescription
utf8::is_utf8(s)Returns 1 if s is well-formed UTF-8.
utf8::valid(s)Alias for utf8::is_utf8.
utf8::encode(s)No-op (strada strings are already bytes).
utf8::decode(s)Validates UTF-8; 1 if valid, 0 if not.
utf8::upgrade(s)No-op; returns s.
utf8::downgrade(s)Returns s if ASCII-only, else dies.
utf8::downgrade(s, 1)Returns s if ASCII, undef if not (fail_ok).
utf8::nfc(s)UAX#15 canonical composition (NFC).
utf8::nfd(s)UAX#15 canonical decomposition (NFD).
utf8::nfkc(s)UAX#15 compatibility composition (NFKC).
utf8::nfkd(s)UAX#15 compatibility decomposition (NFKD).
utf8::normalize(form, s)Generic entry; form = "NFC"/"NFD"/"NFKC"/"NFKD".

Bare built-ins (no namespace)

These match Perl built-ins. The most common are listed below; see BUILTIN_FUNCTIONS.md for the full alphabetical listing and signature details.

Namespaced aliases (preferred for non-Perl built-ins)

Strada-specific built-ins that historically lived in the bare namespace now have preferred namespaced spellings; the bare names keep working as legacy aliases:

Both spellings compile to identical code. Perl-heritage built-ins (say, push, substr, ...) stay unqualified.

Strings

length, lc/lower, uc/upper, lcfirst, ucfirst, chomp, chop, chr, ord, reverse, substr, index, rindex, sprintf, printf, join, split, trim, ltrim, rtrim, quotemeta, re::match, re::replace, re::replace_all, str::replace, re::captures, re::named_captures, pos, pack, unpack.

Numbers

abs, int, hex, rand, srand.

Arrays

push, pop, shift, unshift, splice, each, sort, nsort, reverse, scalar, map, grep, array_new, clone, reserve, deref, derefto, deref_array, deref_hash, deref_set.

Hashes

keys, values, each, exists, delete, hash_new, hash_get, hash_set, tie, untie, tied.

References & OOP

ref, reftype, is_ref, is_refto, bless, blessed, isa, can, UNIVERSAL::isa, UNIVERSAL::can, inherit.

Misc

defined, print, say, printf, warn, die, eval, caller, time, gmtime, localtime, wait, waitpid, fork, exec, exit, system, getpid, dumper, dumper_str, clone, cast_int, cast_num, cast_str.

Special constants: __PACKAGE__, __FILE__, __LINE__, __program_name.

See also