Proposed Changes to the Range API for Phobos v3

monkyyy crazymonkyyy at gmail.com
Fri May 17 01:30:06 UTC 2024


On Thursday, 16 May 2024 at 22:21:54 UTC, Jonathan M Davis wrote:
>
> The new range API is quite explictly _not_ trying to do any 
> explicit Unicode handling.

my proposal of adding .key to the range api isnt unicode spefic 
either

> It's also not efficient to operate at the grapheme level by 
> default.

Anything lazy will be fine; the dstring conversion was slow 
because it had to allocate eagerly

> and no normalization scheme actually works in all cases, making 
> selecting a default problematic.

Im very much for "range starters"; my example code is wildly 
verbose for me and had one

but I view it as *only half the problem*; strings index weird, 
this is trivial to deal with if you have two counters in the same 
abstraction; I believe if effencly impossible to handle by piling 
on more complexity

> So, we can build ***whatever useful algorithms*** or types we 
> want on top of the built-in strings


*I disagree*; I believe the majority of searching should be 
replaced with an "indexes" function

`auto indexes(alias F,R)(R r)=>r.filter!F.swapkeyvalue;`

such a function depends on having a .key concept in the api; and 
then you have the unicode range have apis for selecting the right 
kind of key-value for your range and it will all just work

> [$ .. 0] never make sense, so no, that won't be supported.

if I define a complex opDollar, I can easily imagine it being 
seen as the "indexing" type, when in fact im using it it to slice 
on a bidirectional datastruct that maybe knows how to handle $/2

```d
struct mydata{
   auto opDollar(){
     struct dollar{
       opBinary!"-"
       opBinary!"/"
```

if the range api makes an assumption that 
`range.opSlice!(typeof(range.opDollar),typeof(range.opDollar))` 
this may break unnecessarily; where opDollar is used in opslicing 
matters, also like add $/2 to the wishlist

>>is [min(i,$-1)] supported?
>_____
while I know such slicing probably isnt on your rader for being 
to magic I unironically like how well it works for the base slice





More information about the Digitalmars-d mailing list