Entry point
Every executable defines ^ (main); the program starts there.
^ = () -> Num => 42 ~ no args/env^ = (args :: []Text) -> Num => args.size ~ command-line arguments^ = (args :: []Text, env :: [|Text => Text|]) -> Num => env.get("HOME") ~ args + environmentArguments & environment. ^ may declare, in order, two typed parameters, filled at
startup:
args :: []Text— the command-line arguments (argv), includingargv[0](the program name), soargs.sizeis always at least 1, andargs[i]is the i-th argument as aText.env :: [|Text => Text|]— the environment, as a Map from each variable’s name to its value. An entryKEY=valueis split on its first=(soKEY=a=bmapsKEYtoa=b); an entry with no=maps the whole string to"". Read a variable withenv.get("HOME")(or<< core.cli’sgetEnv), both givingOk(value)/NotOk.
args is a real Quilon array (.size, [index], the array methods) and env a real Map
(.get/.has/.keys/.size). A value read out of either is a full Text: the whole
Text API, and overload dispatch by its concrete type.
quilon run <file> [args...] and a native build agree on args. Under run, the
program sees argv = [<file>, <args...>]: the quilon/run CLI prefix is stripped and
the .qn path becomes argv[0]. So quilon run f.qn a b c gives the same args.size
and trailing arguments as a native ./f a b c — argv[0] is the .qn path rather than
the compiled binary’s path, but everything the program indexes past it matches. (The
legacy ^ = (argc :: Num, argv :: Num) form, where argv was a placeholder 0, still
compiles for backward compatibility but is superseded by args :: []Text.) Any other
^ signature (e.g. a non-Text array element, or an unexpected parameter) is a
compile-time error, reported by check as well as run/build.
Exit code: if ^’s body evaluates to a Num, that value is the exit code. If the body is not a Num (e.g. a side-effecting block), the program exits 0 — so an effect-only main needs no trailing 0. (This implicit-0 applies only to ^; ordinary functions always return their last expression’s value.)
(See examples/hello_world.qn and examples/args.qn.)