Tanguv0.32.0
/fs/io/path/os/os/well-known/process/runtime/thread/coro/tracing/panic

System, filesystem & I/O

Filesystem operations (/fs), buffered I/O (/io), path manipulation (/path), processes (/process), OS threads (/thread), and async coroutines (/coro).

Module /fs #

Filesystem operations: reading, writing, copying, moving, directory traversal, globbing, and path canonicalization.

(use /fs)

canonicalize #

(fs/canonicalize path) -> String

Resolves relative paths, symlinks, and .. segments to an absolute normalized path.

(let abs-path (fs/canonicalize "../config.json"))

close #

(close handle) -> None

Closes the underlying connection, pool, file descriptor, or stream.

copy #

(fs/copy source target) -> Int

Copies source file to target destination, returning bytes copied.

(fs/copy "a.txt" "b.txt")

copy-directory #

(copy-directory ...)

Exported function in /fs.

create #

(create ...)

Exported function in /fs.

create-directory #

(fs/create-directory path) -> Bool

Recursively creates the directory at path (equivalent to mkdir -p).

(fs/create-directory "./build/dist")

exists? #

(fs/exists? path) -> Bool

Returns true if the file or directory at path exists, otherwise false.

(if (fs/exists? "./data.json") (echo "found") (else (echo "missing")))"

flush #

(flush writer) -> None

Flushes all buffered output bytes in writer to the underlying OS stream.

get-current-dir #

(fs/get-current-dir) -> String

Returns the absolute path of the current working directory.

is-directory? #

(fs/is-directory? path) -> Bool

Returns true if path exists and points to a directory.

is-file? #

(fs/is-file? path) -> Bool

Returns true if path exists and points to a regular file.

list #

(fs/list path) -> List

Lists file and folder paths in the directory. Accepts optional {:include-dirs true}.

(let files (fs/list "."))

list-as-tree #

(fs/list-as-tree path) -> List

Recursively walks directory and returns hierarchy tree.

open #

(open ...)

Exported function in /fs.

read #

(read ...)

Exported function in /fs.

read-all #

(read-all reader) -> Slab

Reads all remaining bytes from reader until EOF into a Slab.

read-byte #

(read-byte reader) -> (Or U8 None)

Reads a single byte (U8) from reader, or returns () at EOF.

read-char #

(read-char reader) -> (Or Char None)

Reads a single UTF-8 Char from reader, or returns () at EOF.

read-line #

(read-line reader) -> (Or String None)

Reads a line of UTF-8 text from reader (stripping trailing newline), or returns () at EOF.

read-slab-from-file #

(fs/read-slab-from-file path) -> Slab

Reads raw bytes of a file into a binary Slab buffer.

read-string #

(read-string reader) -> String

Reads all remaining UTF-8 text from reader until EOF into a String.

read-string-from-file #

(fs/read-string-from-file path) -> String

Reads the complete UTF-8 contents of a file at path into a String. Returns an Error if the file cannot be read.

(let content (fs/read-string-from-file "config.json"))

remove-directory #

(fs/remove-directory path) -> Bool

Recursively removes the directory at path and all its contents.

(fs/remove-directory "./tmp")

remove-file #

(remove-file ...)

Exported function in /fs.

rename #

(fs/rename from to) -> Bool

Renames or moves a file or directory from one path to another.

(fs/rename "old.txt" "new.txt")

write #

(write ...)

Exported function in /fs.

write-byte #

(write-byte writer byte) -> None

Writes a single byte (U8) to writer.

write-line #

(write-line writer line) -> None

Writes line followed by a newline character to writer.

write-slab-to-file #

(fs/write-slab-to-file path slab) -> Int

Writes binary Slab buffer to file at path. Returns number of bytes written.

write-string #

(write-string writer str) -> None

Writes a UTF-8 String to writer.

write-string-to-file #

(fs/write-string-to-file path content) -> Int

Writes content to path, automatically creating parent directories if necessary. Returns the number of bytes written.

(fs/write-string-to-file "./output/log.txt" "Task completed.")

writeln #

(writeln ...)

Exported function in /fs.

Module /io #

Buffered and standard stream I/O (Buf-Reader, Buf-Writer, Stdin, Stdout, Stderr, read-line, write-line, flush, and ask).

(use /io)

Buf-Reader #

(Func Any Any)

Wraps an input stream or file handle in a buffered reader.

Buf-Writer #

(Func Any Any)

Wraps an output stream or file handle in a buffered writer.

Stderr #

(Stderr) -> Stream

Returns a handle to the standard error stream (stderr).

Stdin #

(Stdin) -> Stream

Returns a handle to the standard input stream (stdin).

Stdout #

(Stdout) -> Stream

Returns a handle to the standard output stream (stdout).

ask #

(Func Any Any)

Prints an optional prompt to stdout, flushes it, and reads a single line of user input from stdin.

flush #

(Func Any Any)

Flushes all buffered output bytes in writer to the underlying OS stream.

read #

(Func [Any Int] Any)

Exported function in /io.

read-all #

(Func Any Any)

Reads all remaining bytes from reader until EOF into a Slab.

read-byte #

(Func Any Any)

Reads a single byte (U8) from reader, or returns () at EOF.

read-char #

(Func Any Any)

Reads a single UTF-8 Char from reader, or returns () at EOF.

read-line #

(Func Any Any)

Reads a line of UTF-8 text from reader (stripping trailing newline), or returns () at EOF.

read-string #

(Func Any Any)

Reads all remaining UTF-8 text from reader until EOF into a String.

stderr #

(stderr ...)

Exported function in /io.

stdin #

(stdin ...)

Exported function in /io.

stdout #

(stdout ...)

Exported function in /io.

write #

(Func [Any Any] Any)

Exported function in /io.

write-byte #

(Func [Any Any] Any)

Writes a single byte (U8) to writer.

write-line #

(Func [Any Any] Any)

Writes line followed by a newline character to writer.

write-string #

(Func [Any Any] Any)

Writes a UTF-8 String to writer.

Module /path #

Cross-platform lexical path manipulation: dirname, filename, extension-of, stem-of, join, and normalize.

(use /path)

basename-of #

(path/basename-of path) -> String

Returns the trailing component of a path.

(path/basename-of "/home/user/doc.txt") -> "doc.txt"

dirname-of #

(path/dirname-of path) -> String

Returns the parent directory portion of a path, or empty string if none.

(path/dirname-of "/home/user/doc.txt") -> "/home/user"

extension-of #

(path/extension-of path) -> String

Returns the full file extension (e.g. "tar.gz", "data.tan"), or empty string if none.

(path/extension-of "archive.tar.gz") -> "tar.gz"

get-dirname #

(Func Any Any)

Exported function in /path.

get-extension #

(Func Any Any)

Exported function in /path.

is-absolute? #

(path/is-absolute? path) -> Bool

Returns true if the path is absolute.

(path/is-absolute? "/usr/bin") -> true

is-relative? #

(path/is-relative? path) -> Bool

Returns true if the path is relative.

(path/is-relative? "src/main.tan") -> true

join #

(path/join ...parts) -> String

Safely joins multiple path segments using platform-specific path separators.

(path/join "src" "bin" "main.tan")

normalize #

(path/normalize path) -> String

Lexically normalizes path by resolving "." and ".." segments without accessing the filesystem.

(path/normalize "a/b/../c") -> "a/c"

path-join #

(Func Any String)

Exported function in /path.

relative-to #

(path/relative-to base target) -> String

Computes the relative path required to navigate from base to target.

(path/relative-to "/a/b" "/a/b/c/d") -> "c/d"

resolve #

(path/resolve ...paths) -> String

Resolves a sequence of paths into an absolute normalized path relative to the current working directory.

(path/resolve "config" "app.json")

split #

(path/split path) -> Array

Splits a path into an Array of its constituent component strings.

(path/split "a/b/c") -> ["a" "b" "c"]

stem-of #

(path/stem-of path) -> String

Returns the file stem (basename minus full extension). Preserves: stem-of + "." + extension-of == basename-of.

(path/stem-of "archive.tar.gz") -> "archive"

Module /os #

Host operating system, CPU architecture, hostname, and environment introspection.

(use /os)

arch #

(os/arch) -> String

Returns the CPU architecture (e.g. "x86_64", "aarch64").

(let target-arch (os/arch))

cpu-count #

(os/cpu-count) -> Int

Returns the number of logical CPU cores available to the current process.

(let concurrency (os/cpu-count))

family #

(os/family) -> String

Returns the operating system family (e.g. "unix", "windows").

(if (= (os/family) "unix") (writeln "POSIX compliant"))

home-dir #

(os/home-dir) -> (Or String ())

Returns the current user's home directory path, or () if not found.

(let home (os/home-dir))

host-name #

(os/host-name) -> String

Returns the network hostname of the host system.

(let host (os/host-name))

os-name #

(os/os-name) -> String

Returns the operating system name (e.g. "linux", "macos", "windows").

(let os (os/os-name))

temp-dir #

(os/temp-dir) -> String

Returns the default directory path for temporary files.

(let tmp (os/temp-dir))

uptime #

(os/uptime) -> Float

Returns system uptime in seconds as a floating-point number.

(let secs (os/uptime))

Module /os/well-known #

Cross-platform XDG / OS standard directories (config-dir, cache-dir, data-dir, home-dir, download-dir).

(use /os/well-known)

cache-dir #

(cache-dir ...)

Exported function in /os/well-known.

config-dir #

(config-dir ...)

Exported function in /os/well-known.

data-dir #

(data-dir ...)

Exported function in /os/well-known.

data-local-dir #

(data-local-dir ...)

Exported function in /os/well-known.

desktop-dir #

(desktop-dir ...)

Exported function in /os/well-known.

document-dir #

(document-dir ...)

Exported function in /os/well-known.

download-dir #

(download-dir ...)

Exported function in /os/well-known.

executable-dir #

(executable-dir ...)

Exported function in /os/well-known.

font-dir #

(font-dir ...)

Exported function in /os/well-known.

get-app-dirs #

(get-app-dirs ...)

Exported function in /os/well-known.

get-user-dirs #

(get-user-dirs ...)

Exported function in /os/well-known.

home-dir #

(home-dir ...)

Exported function in /os/well-known.

music-dir #

(music-dir ...)

Exported function in /os/well-known.

picture-dir #

(picture-dir ...)

Exported function in /os/well-known.

preference-dir #

(preference-dir ...)

Exported function in /os/well-known.

public-dir #

(public-dir ...)

Exported function in /os/well-known.

runtime-dir #

(runtime-dir ...)

Exported function in /os/well-known.

state-dir #

(state-dir ...)

Exported function in /os/well-known.

template-dir #

(template-dir ...)

Exported function in /os/well-known.

video-dir #

(video-dir ...)

Exported function in /os/well-known.

Module /process #

Subprocess execution (exec, spawn), environment variables (env, env-vars), working directory, and exit codes.

(use /process)

args #

(process/args) -> Array

Returns the array of command-line arguments passed to the running script.

(let [file target] (process/args))

env #

(process/env) -> Map

Reads environment variables. With 0 args returns a Map of all vars; with 1 arg returns the value or (); with 2 args returns fallback when unset.

(let vars (process/env))
(let port (process/env "PORT" "8080"))

env-vars #

(Func Any Any)

Exported function in /process.

exec #

(process/exec cmd) -> String

Executes a shell command and captures its standard output as a String.

(let out (process/exec "git rev-parse HEAD"))

exit #

(Func Any Any)

Exported function in /process.

exit! #

(process/exit! [code]) -> Never

Immediately terminates the current process with the given integer exit code (defaults to 0).

(process/exit! 1)

expect-env-var #

(name)

Returns the value of the environment variable name, or panics if undefined.

get-args #

(Func () Array)

Exported function in /process.

get-env #

(Func () Map)

Exported function in /process.

has-env? #

(process/has-env? name) -> Bool

Returns true if the environment variable is set in the current process.

(if (process/has-env? "DEBUG") (writeln "debugging enabled"))

pid #

(process/pid) -> Int

Returns the current process identifier (PID).

(let current-pid (process/pid))

run #

(process/run cmd) -> Map

Executes a subprocess directly without invoking sh -c, preventing shell command injection and returning {:status Int :stdout String :stderr String :ok Bool}.

(let res (process/run ["git" "status" "--porcelain"]))
(let res (process/run ["env"] {:clear-env true :env {:MODE "safe"}}))

set-env #

(process/set-env name value) -> ()

Sets an environment variable for the current process.

(process/set-env "API_KEY" "secret")

set-env-var #

(Func String String String)

Exported function in /process.

shell #

(process/shell cmd) -> Int

Executes a shell command streaming standard I/O to the console, returning the exit status code.

(let code (process/shell "npm test"))

unset-env #

(process/unset-env name) -> ()

Unsets an environment variable from the current process.

(process/unset-env "API_KEY")

Module /runtime #

Multi-threaded Tokio async runtime management (Async-Runtime, run, block-on).

(use /runtime)

Async-Runtime #

(Func [] AsyncRuntime)

Exported function in /runtime.

Async-Runtime-construct #

(Func [] AsyncRuntime)

Exported function in /runtime.

block-on #

(block-on ...)

Exported function in /runtime.

run #

(rt func)

Exported function in /runtime.

Module /thread #

OS thread spawning, sleeping, and parallel task synchronization (spawn, sleep, await, await-all).

(use /thread)

await #

(await ...)

Exported function in /thread.

await-all #

(await-all ...)

Exported function in /thread.

sleep #

(sleep ...)

Exported function in /thread.

spawn #

(spawn ...)

Exported function in /thread.

Module /coro #

Lightweight cooperative coroutines (spawn, await) and multi-producer/multi-consumer channels (channel, send, recv).

(use /coro)

await #

(Func [Coro-Future] Any)

Exported function in /coro.

await-all #

(Func Any Any)

Exported function in /coro.

channel #

(coro/channel) -> Channel

Creates an async FIFO communication channel.

recv #

(coro/recv channel) -> Any

Receives a message from channel, yielding execution until one is available.

send #

(coro/send channel message) -> ()

Sends a value into the channel.

sleep #

(Func Int None)

Exported function in /coro.

spawn #

(coro/spawn (Func [] ...)) -> Task

Spawns a non-blocking asynchronous coroutine task.

Module /tracing #

Structured diagnostic logging (trace, debug, info, warn, error) with pluggable observer sinks.

(use /tracing)

Default-Tracing-Observer #

(port)

Exported function in /tracing.

add-tracing-observer #

(observer)

Exported function in /tracing.

debug #

(event)

Exported function in /tracing.

error #

(event)

Exported function in /tracing.

info #

(event)

Exported function in /tracing.

is-level-enabled #

(level)

Exported function in /tracing.

next-event #

(ob level event)

Exported function in /tracing.

set-tracing-level #

(level)

Exported function in /tracing.

start #

(observers)

Exported function in /tracing.

stop #

(...)

Exported function in /tracing.

trace #

(event)

Exported function in /tracing.

warn #

(event)

Exported function in /tracing.

Module /panic #

Unrecoverable developer error macros and placeholders (todo!, unimplemented!).

(use /panic)

todo! #

(text)

Exported function in /panic.

unimplemented! #

(text)

Exported function in /panic.

unreachable! #

(Func [Any] Any)

Exported function in /panic.