Environment Variables in Scheme
Environment variables are a universal mechanism for conveying configuration information to Unix programs. Let’s look at how to set, get, and list environment variables in Scheme.
Running the program shows that we pick up the value for FOO
that we set in the program, but that BAR
is empty (represented as #f
in Scheme).
The list of keys in the environment will depend on your particular machine.
If we set BAR
in the environment first, the running program picks that value up:
In Scheme, we use setenv
to set environment variables and getenv
to retrieve them. The environ
variable gives us access to all environment variables as an association list. We can use Scheme’s list processing functions to work with this data.
Note that the exact behavior might vary slightly depending on the Scheme implementation you’re using. This example uses GNU Guile, which is one of the more popular Scheme implementations.