std.v2020.algorithm etc[ WAS: Is run.d going to be expand for runtime and the phobos library?]

FeepingCreature feepingcreature at gmail.com
Mon Jun 22 12:28:06 UTC 2020


On Monday, 22 June 2020 at 12:15:39 UTC, Steven Schveighoffer 
wrote:
> On 6/20/20 8:12 PM, Andrei Alexandrescu wrote:
>> On 6/20/20 3:03 PM, Steven Schveighoffer wrote:
>>> On 6/20/20 6:43 AM, Paul Backus wrote:
>>>> On Saturday, 20 June 2020 at 04:34:42 UTC, H. S. Teoh wrote:
>>>>> On Fri, Jun 19, 2020 at 09:14:30PM -0400, Andrei 
>>>>> Alexandrescu via Digitalmars-d wrote: [...]
>>>>>> One good goal for std.v2020 would be to forego 
>>>>>> autodecoding throughout.
>>>>> [...]
>>>>>
>>>>> Another could be to fix up the range API -- i.e, reconsider 
>>>>> the ugliness that is .save, now that D has copy ctors.
>>>>>
>>>>>
>>>>
>>>> Also, switch from `void popFront()` to `typeof(this) rest`, 
>>>> so that we can have `const` and `immutable` ranges.
>>>
>>> How does that work? You'd have to use recursion I guess? 
>>> ugly. Why do we need ranges for something like this?
>> 
>> Think Hakell lists. They can implement tail easily (just 
>> return the next pointer) but can't define popFront.
>> 
>
> My question wasn't about how such a thing could be implemented, 
> but how it works with const ranges.
>
> foreach(x; someConstRange) I think wouldn't be possible. I 
> think you'd have to recurse:
>
> void process(const Range r)
> {
>    subProcess(r.front);
>    process(r.rest);
> }
>

I think maybe what is needed is a notion of "head-mutable"?

void process(const headmut Range r)
{
   while (!r.empty) {
     // subProcess still has to take an immmutable r. this does 
not expose mutable state.
     // headmut converts to immutable on pass-by-value because it 
makes a copy.
     subProcess(r.front);
     r = r.rest; // can be assigned because headmut, meaning 
references are still immutable
   }
}

I don't know how this would interact with dip1000. Maybe headmut 
could convert as immutable but expression scoped, which would 
come down to the same thing.

Something like this is also probably the right backing type to 
use for many containers, like Nullable.


More information about the Digitalmars-d mailing list