Files, Paths, And IO

Warning

This is the current planned CLEAR stdlib design. Full stdlib implementation and stabilization are not planned until v0.3. Treat these pages as design direction, not as a compatibility promise.

Status: planned, self-host required.

File and network IO should be high-level by default. Users should not need Java-style object stacks or Zig-style explicit buffer plumbing for common work.

High-Level File API

APIStatusNotes
fs.read(path)prototype, self-host requiredRead full UTF-8 text, returns !String.
fs.readBytes(path)planned, self-host requiredRead full byte buffer.
fs.readLines(path)planned, self-host requiredTarget return: !~String[], a fallible stream of lines.
fs.write(path, content)prototype, self-host requiredWrite text, returns !Void.
fs.append(path, content)plannedTooling convenience.
fs.exists?(path)self-host requiredFile or directory exists.
fs.file?(path)self-host requiredRegular file predicate.
fs.dir?(path)self-host requiredDirectory predicate.
fs.symlink?(path)self-host requiredSymlink predicate.
fs.size(path)prototype, self-host requiredFile size, returns !Int64; current wrapper converts the old sentinel intrinsic to fallibility.
fs.mtime(path)self-host requiredFile modified time.
fs.list(path)planned, self-host requiredUnsorted stream of directory entries.
fs.glob(pattern)planned, self-host requiredUnsorted stream of matching paths.
source = fs.read("src/ast/parser.cht") OR RAISE;
lines = fs.readLines("src/ast/lexer.cht") OR RAISE;
fs.write("build/report.txt", report) OR RAISE;

ordered_files = (fs.glob("src/**/*.cht") OR RAISE)
    |> ORDER_BY _;

The current pkg:fs prototype can compile read, collected readLines, write, and fallible size over existing intrinsics. The desired readLines(path) RETURNS !~String[] surface is blocked on parser/type support for a fallible stream container.

Stateful File API

Stateful handles exist for large inputs, streaming, explicit lifetime, and performance-sensitive code. They should not be required for simple reads and writes.

file = fs.open("events.log");
recent = file.lines()
    |> SELECT { _.contains?("ERROR") }
    |> COLLECT_LIST;

Path API

APIStatusNotes
path.join(parts...)self-host requiredReplacement for File.join.
path.expand(path, base?)self-host requiredReplacement for File.expand_path.
path.basename(path, suffix?)self-host requiredReplacement for File.basename.
path.dirname(path)self-host requiredReplacement for File.dirname.
path.relative(from, to)plannedTooling convenience.

Decisions

Source: docs/stdlib/files-and-io.md