March Docs

System

System module: OS and runtime information.

Exposes host OS/arch detection, process metadata, environment variables, and subprocess execution under a unified System namespace.

Usage: System.os() -- "macos" | "linux" | "windows" | "unknown" | ... System.arch() -- "x86_64" | "aarch64" | "x86" | ... System.cpu_count() -- number of logical CPUs System.monotonic_time() -- milliseconds since process start System.env("PATH") -- Some(value) | None System.put_env("KEY", "val") System.argv() -- List(String) System.cwd() -- String System.pid() -- Int System.exit(0) -- terminate process System.cmd("ls", ["-la"]) -- Ok(ProcessResult) | Err(msg) System.version() -- the compiler's version, e.g. "0.4.0"

Functions

fnarcharch() : String#

Return the host CPU architecture as a lowercase String: "x86_64", "aarch64", "x86", or the lowercased uname machine name.

fnargvargv() : List(String)#

Return command-line arguments as List(String). argv()[0] is the path to the executable.

fncmdcmd(command : String, args : List(String)) : Result(ProcessResult, String)#

Run an external command synchronously, capturing stdout. Returns Ok(ProcessResult(exit_code, stdout, stderr)) or Err(msg); a missing or non-executable command is Err("cannot execute <cmd>: <reason>").

match System.cmd("git", ["status"]) do
Ok(r)    -> println(System.stdout(r))
Err(msg) -> IO.warn("cmd failed: " ++ msg)
end
fncpu_countcpu_count() : Int#

Return the number of logical CPUs available to the runtime.

fncpu_load_millicpu_load_milli() : Int#
  1. Divide by cpu_count() to

get a rough per-core utilization figure. Returns 0 when unavailable.

let busy_milli = System.cpu_load_milli() / System.cpu_count()
fncwdcwd() : String#

Return the current working directory as a String.

fnenvenv(name : String) : Option(String)#

Get the value of an environment variable. Returns Some(value) if set, None if not set.

fnexitexit(code : Int) : Unit#

Terminate the process with the given exit code.

fnexit_codeexit_code(r : ProcessResult) : Int#

Extract the exit code from a ProcessResult.

fnmem_available_bytesmem_available_bytes() : Int#

Available (free + reclaimable) memory in bytes (0 if unavailable).

fnmem_peak_bytesmem_peak_bytes() : Int#

Peak resident set size of this process so far, in bytes, on both macOS and Linux. Ambient — no capability needed, since it performs no IO and observes nothing outside this process.

Interpreted and compiled runs are NOT comparable: the interpreter has no getrusage and approximates with the OCaml heap size instead of true process RSS, so only relative ordering (a later call >= an earlier one) is guaranteed to agree between the two, never raw numbers.

let before = System.mem_peak_bytes()
-- ... allocate ...
let after = System.mem_peak_bytes()
let grew = after - before

Named mem_peak_bytes rather than peak_rss_bytes to avoid shadowing the peak_rss_bytes builtin it wraps — a same-named local fn recurses into itself instead of reaching the builtin.

fnmem_total_bytesmem_total_bytes() : Int#

Total physical memory in bytes (0 if unavailable).

fnmonotonic_timemonotonic_time() : Int#

Return milliseconds elapsed since the process started. Suitable for rough timing; not a wall-clock time.

let t0 = System.monotonic_time()
-- ... work ...
let elapsed = System.monotonic_time() - t0
fnokok(r : ProcessResult) : Bool#

True if the command exited with code 0.

fnosos() : String#

Return the host operating system as a lowercase String: "macos", "linux", "windows", "unknown", or the lowercased uname sysname.

if System.os() == "macos" do "brew" else "apt" end
fnpidpid() : Int#

Return the OS-level PID of the current process as an Int.

fnput_envput_env(name : String, value : String) : Unit#

Set an environment variable.

fnstderrstderr(r : ProcessResult) : String#

Extract captured stderr from a ProcessResult.

fnstdoutstdout(r : ProcessResult) : String#

Extract captured stdout from a ProcessResult.

fnversionversion() : String#

Return the version of the March compiler that built (or is running) this program, e.g. "0.4.0". Interpreted and compiled runs agree.