The new std.process is ready for review

Lars T. Kyllingstad public at kyllingen.net
Tue Mar 12 01:58:12 PDT 2013


On Tuesday, 12 March 2013 at 08:28:02 UTC, Vladimir Panteleev 
wrote:
> On Tuesday, 12 March 2013 at 07:41:03 UTC, Lars T. Kyllingstad 
> wrote:
>> On Wednesday, 6 March 2013 at 07:27:19 UTC, Lars T. 
>> Kyllingstad wrote:
>>> On Tuesday, 5 March 2013 at 21:04:15 UTC, Vladimir Panteleev 
>>> wrote:
>>>> 5. How about that Environment.opIn_r?
>>>
>>> Forgot about it. :)  I'll add it.
>>
>> So I sat down to write this function, but then I reconsidered.
>>  The thing is, checking whether the variable exists is exactly 
>> the same operation as retrieving it.  In other words, this:
>>
>>   if (key in environment)
>>   {
>>       auto val = environment[key];
>>       ...
>>   }
>>
>> is equivalent to:
>>
>>   if (environment.get(key) !is null)
>>   {
>>       auto val = environment.get(key);
>>       ...
>>   }
>
> Yes, it's just syntax sugar, and an operation supported by AAs 
> (which environment imitates). It's useful if you don't want to 
> retrieve the value of a variable right after checking if it 
> exists - you just want to see if it's there or not.

For AAs, 'in' returns a pointer to the element, which is null if 
the element does not exist.  I can't think of a good way to 
implement this.  Since we have to convert the raw environment 
variable to a D string anyways, we'd have to do something like:

   string* opIn_r(string var)
   {
       auto val = get(var);
       if (val is null) return null;
       else return [val].ptr;
   }

but that seems rather pointless to me.

Lars


More information about the Digitalmars-d mailing list