DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Ada.Environment_Variables

The process's environment variables (RM A.17).

Read the family guide for representation, selection and resource rules. The complete declaration page retains exact signatures/contracts; the source specification is the implementation baseline.

Availability and ownership

All of RM A.17, over the host's environment. Where Ada raises Constraint_Error, a precondition rules the case out; the ghost Model states a variable's value in contracts.

A client proof uses these contracts without proving the body again (see library assurance). Global => null excludes package-global effects, not changes made through an in out argument.

Import and instantiate

with Ada.Environment_Variables;
import Ada.Environment_Variables;

A Vibe module imports this unit's names with from Ada.Environment_Variables import Name; see library use across syntaxes. In Varc, keep each name's declared spelling and write & on arguments the call changes.

Contract and lifecycle reading

A Pre condition is the caller's obligation; a Post is what a normal return guarantees. What a postcondition does not state, a client cannot assume. Ghost functions are for contracts and ghost code. The family guide describes copying, lifetime, order and cost.

API 001

Is_Name (declaration) — Whether a string may name a variable: not empty, with no = and no NUL.

Declared interface:

function Is_Name (Name : String) return Boolean is
  (Name'Length > 0 and then (for all I in Name'Range => Name (I) /= '=' and then Name (I) /= Character'Val (0)))
  with Global => null;

API 002

Is_Value (declaration) — Whether a string may be a variable's value: no NUL.

Declared interface:

function Is_Value (Value : String) return Boolean is
  (for all I in Value'Range => Value (I) /= Character'Val (0))
  with Global => null;

API 003

Exists (declaration) — Whether the variable Name exists.

Declared interface:

function Exists (Name : String) return Boolean
  with Global => Environment;

API 004

Model (declaration) — Ghost: the variable's value (empty when it does not exist), for contracts.

Declared interface:

function Model (Name : String) return String
  with Ghost, Import, Global => Environment,
       Post => Model'Result'Length < Verada.Storage.Length_Bound
               and then (Model'Result'Length = 0 or else Model'Result'First = 1);

API 005

Value (declaration) — The variable's value, Model (Name); it must exist.

Declared interface:

function Value (Name : String) return String
  with Global => Environment,
       Pre => Exists (Name),
       Post => Value'Result = Model (Name)
               and then (Value'Result'Length = 0 or else Value'Result'First = 1);

API 006

Value (declaration) — The variable's value, or Default when it does not exist.

Declared interface:

function Value (Name : String; Default : String) return String
  with Global => Environment,
       Post => (if Exists (Name) then Value'Result = Model (Name) else Value'Result = Default);

API 007

Set (declaration) — Sets the variable Name to Value, creating it if need be; then Model (Name) = Value.

Declared interface:

procedure Set (Name : String; Value : String)
  with Global => (In_Out => Environment),
       Pre => Is_Name (Name) and then Is_Value (Value),
       Post => Exists (Name) and then Model (Name) = Value;

API 008

Clear (declaration) — Removes the variable Name, if it exists.

Declared interface:

procedure Clear (Name : String)
  with Global => (In_Out => Environment),
       Post => not Exists (Name) and then Model (Name)'Length = 0;

API 009

Clear (declaration) — Removes every variable.

Declared interface:

procedure Clear
  with Global => (In_Out => Environment);

API 010

Iterate (declaration) — Calls Process with each variable's name and value, as they were when Iterate began.

Declared interface:

procedure Iterate (Process : not null access procedure (Name, Value : String))
  with Global => (In_Out => Environment);