Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Environment

The environment is your program's practical link to the outside world. Most programs meet it first as the env argument passed to the root actor.

actor main(env):
    print("args:", env.argv)
    env.exit(0)

You can think of env as the handle your program receives for talking to the world around it. It is passed into main; it is not a hidden global that every function can reach automatically. If a helper only needs one small piece of that power, pass the smaller piece instead of the whole environment.

From there, this chapter covers the most common environment tasks:

Use env when code needs process arguments, environment variables, standard input, or terminal configuration. Pass it only to the code that actually needs that access.

env is best understood as a bundle of process-level capabilities, not as one ordinary argument. It carries authority over things such as arguments, environment variables, standard input, and terminal configuration. If that whole bundle gets threaded through many layers, those layers quietly become coupled to process concerns even when they only need one small part of it.

In larger programs, treat the root actor as the place where broad authority is received, then pass inward only the narrower capability or value a helper actually needs. That keeps APIs honest about what they depend on, makes tests easier to fake, and prevents a small utility from accidentally gaining much wider access to the outside world than its job requires.