On Mon, Dec 9, 2019 at 5:39 AM Lassi Kortela <xxxxxx@lassi.io> wrote:

One more use case: Common Lisp has an `ed` function that launches a text
editor. I have a pending SRFI that provides that for Scheme, and it'd be
nice to use (get-environment-variable "EDITOR") to figure out which
editor to use in a Unix terminal.
 
Capture the value of $EDITOR (actually you are supposed to look at $VISUAL first, and if it is undefined then look at $EDITOR) in a variable of  the (ed) library.  Then just use that variable henceforth.  You can expose a set-editor! procedure to change it.

This would mean that C code running via FFI and using libc getenv() has
a different view of the environment variables than Scheme code does. It
also means that any Schemes implementing SRFI 98  
`get-environment-variable` need to change that implementation to take
the environment parameter into account.  

The above ideas avoid this.  If your program doesn't change any environment variables, use get-environment-variable freely.  If it does, capture the whole environment early in a global variable as an alist, search it with assoc, push things on the alist as you will, and pass it to all calls to spawn-process. (I have updated ProcessesCowan to make it clear that if the same key appears more than once, the first value is put into the environment by spawn-process.)

A lot of the complications probably come from the fact that memory was
tight in the 1980s, so they couldn't just strdup() all strings at the
API boundary. 

Not just that, but because putenv() can be used for dynamic binding without leaks, as I explained.

We could also write a separate SRFI as a follow-up to SFI 98 with just
set-environment-variable! and delete-environment-variable! :) As was
done with the timespec SRFI. 

They are Posix but not C, so if they belong anywhere at all (and I think they don't), it's in the Posix SRFI. 
 
John Cowan          http://vrici.lojban.org/~cowan        xxxxxx@ccil.org
The Imperials are decadent, 300 pound free-range chickens (except they have
teeth, arms instead of wings, and dinosaurlike tails).  --Elyse Grasso