The new std.process is ready for review

dennis luehring dl.soluz at gmx.net
Tue Mar 12 23:45:57 PDT 2013


Am 13.03.2013 07:31, schrieb Lars T. Kyllingstad:
> On Wednesday, 13 March 2013 at 03:27:25 UTC, Vladimir Panteleev
> wrote:
>> On Tuesday, 12 March 2013 at 21:39:47 UTC, Steven Schveighoffer
>> wrote:
>>>> I'd be very interested to hear if you have a suggestion for a
>>>> better way to do it, keeping in mind that there needs to be
>>>> *some* way to clear the environment too.
>>>
>>> Sadly, no I don't.  I had hoped [] would allocate an empty AA,
>>> but it fails to compile.
>>>
>>> Note that you can "hack" it by setting a single environment
>>> variable which nobody will ever use.
>>>
>>> i.e. spawnProcess("blah.exe", ["_____":"_____"]);
>>>
>>> But that is really, really ugly.
>>
>> How about this:
>>
>> @property string[string] emptyEnvironment()
>> {
>>     string[string] result;
>>     result["a"] = "a";
>>     result.remove("a");
>>     assert(result && result.length == 0);
>>     return result;
>> }
>>
>> (can be cached to avoid allocating each time)
>
> That's a lot better than ["____":"_____"], at least. :)
>
> But still, the difference between a null AA and an empty AA is
> still very subtle, and I am hesitant to design an API that
> depends on it.  We'd have to explain to the users that "ok, so
> there are two kinds of empty AAs: the ones you've done nothing
> with, and the ones you've added and removed a value from..."
>
> Furthermore, the language spec doesn't seem to mention "null" in
> relation to AAs.  Shouldn't the difference between null and empty
> then be treated as an implementation detail?  Can we even be sure
> that "aa is null" will work in two years?
>
> Lars
>

why not differentiate on callsite?

like

environment_usage =
{
   PARENT_ENVIRONMENT,
   NONE_ENVIRONMENT, // which differs from empty given environment
   GIVEN_ENVIRONMENT
}

spawnProcess(process,parameter,environment_usage = PARENT_ENVIRONMENT, 
environemnt = null)

it feels very wrong to put the environment "usage" type in any way into 
the environment-abstraction itself (by occupying null or empty...)

+some nice helpers

spawnProcessWithParentEnvironment((process,parameter)
spawnProcessWithoutEnvironment((process,parameter)
spawnProcessWithEnvironment((process,parameter,environment=...)

woulnd't that be much clearer?

the other way could be an

spawnProcess(process,parameter,environment=use_parent_environment());
with parent-environment selector

spawnProcess(process,parameter,environment=given_environment(environment));





More information about the Digitalmars-d mailing list