The Case Against Autodecode

Andrew Godfrey via Digitalmars-d digitalmars-d at puremagic.com
Mon May 30 13:00:19 PDT 2016


On Monday, 30 May 2016 at 18:26:32 UTC, Adam D. Ruppe wrote:
> On Monday, 30 May 2016 at 17:14:47 UTC, Andrew Godfrey wrote:
>> I like "make string iteration explicit" but I wonder about 
>> other constructs. E.g. What about "sort an array of strings"? 
>> How would you tell a generic sort function whether you want it 
>> to interpret strings by code unit vs code point vs grapheme?
>
> The comparison predicate does that...
>
> sort!( (string a, string b) {
>   /* you interpret a and b here and return the comparison */
> })(["hi", "there"]);

Thanks! You left out some details but I think I see - an example 
predicate might be "cmp(a.byGrapheme, b.byGrapheme)" and by the 
looks of it, that code works in D today.

(However, "cmp(a, b)" would default to code points today, which 
is surprising to almost everyone, and that's more what this 
thread is about).


More information about the Digitalmars-d mailing list