get_env(+atom_var, ?atom_value)

This built-in predicate retrieves the value for an existing environment variable and unifies that value with the second argument. Only the environment of the current process can be queried. If the value of the environment variable was successfully queried and unified with the second parameter then the predicate is exited, else it fails.

see also: del_env/1 set_env/2

Examples
set_env('test', 'house'),
get_env('test', A).
If the environment of the current process has no variable called 'test' then a new variable is added with the value 'house'. With get_env/2 the value of 'test' is unified with A,
A = 'house'
set_env('test', 'house'),
get_env('test', 'office').
The value of the environment variable 'test' is set to 'house' and then the value of 'test' is unified with 'office', this unification fails, so get_env/2 fails.

 

Exceptions
The first argument is a variable an instantiation_error exception is thrown
The first argument Arg is not an atom a type_error(atom, Arg) exception is thrown
The second argument Arg is not an atom nor a variable a type_error(atom, Arg) exception is thrown

 

 

info@trinc-prolog.com