digitalmars.D.learn - Sort using Uniform call syntax
- Jerry (5/5) Mar 14 2016 I have a small problem with using UCS when sorting arrays. This
- =?UTF-8?Q?Ali_=c3=87ehreli?= (8/13) Mar 14 2016 Two options:
- Jonathan M Davis via Digitalmars-d-learn (6/18) Mar 14 2016 Yep. The sort property on arrays will likely go away eventually, but unt...
- =?UTF-8?Q?Ali_=c3=87ehreli?= (28/52) Mar 14 2016 Do you mean property sort would sort individual chars? However, the
- Jonathan M Davis via Digitalmars-d-learn (6/39) Mar 14 2016 It was my understanding that the built-in sort did indeed sort individua...
I have a small problem with using UCS when sorting arrays. This pops a warning telling me to use the algorithm sort instead of the property sort. Which I understand why it works that way. However that means I can not have syntactic sugar. So is there any way around this or do I just have to live with it?
Mar 14 2016
On 03/14/2016 04:01 AM, Jerry wrote:I have a small problem with using UCS when sorting arrays. This pops a warning telling me to use the algorithm sort instead of the property sort. Which I understand why it works that way. However that means I can not have syntactic sugar. So is there any way around this or do I just have to live with it?Two options: a) Use parentheses after sort: arr.sort() b) Import sort() under a different name: import std.algorithm: algsort = sort; arr.algsort Ali
Mar 14 2016
On Monday, March 14, 2016 04:14:26 Ali Çehreli via Digitalmars-d-learn wrote:On 03/14/2016 04:01 AM, Jerry wrote: > I have a small problem with using UCS when sorting arrays. This pops a > warning telling me to use the algorithm sort instead of the property > sort. Which I understand why it works that way. However that means I can > not have syntactic sugar. So is there any way around this or do I just > have to live with it? Two options: a) Use parentheses after sort: arr.sort() b) Import sort() under a different name: import std.algorithm: algsort = sort; arr.algsortYep. The sort property on arrays will likely go away eventually, but until it does, those are your options. But at least now it warns you. Previously, it just silently used the sort property, which does the wrong thing for arrays of char or wchar. - Jonathan M Davis
Mar 14 2016
On 03/14/2016 06:56 AM, Jonathan M Davis via Digitalmars-d-learn wrote:On Monday, March 14, 2016 04:14:26 Ali Çehreli via Digitalmars-d-learn wrote:Do you mean property sort would sort individual chars? However, the following program indicates that it may have been fixed (i.e. made Unicode-aware): import std.stdio; void main() { auto arr = "çöüabc".dup; arr.sort; // (Not correct for a particular writing system but // that's beyond the point. It's still a correct string.) assert(arr == "abcçöü"); foreach (c; arr) { writefln("%02x", c); } } Prints: 61 62 63 c3 <- Out of order a7 <- etc. c3 b6 c3 bc Perhaps, this was an independent change? More likely I've misunderstood you. :) AliOn 03/14/2016 04:01 AM, Jerry wrote: > I have a small problem with using UCS when sorting arrays. This pops a > warning telling me to use the algorithm sort instead of the property > sort. Which I understand why it works that way. However that means I can > not have syntactic sugar. So is there any way around this or do I just > have to live with it? Two options: a) Use parentheses after sort: arr.sort() b) Import sort() under a different name: import std.algorithm: algsort = sort; arr.algsortYep. The sort property on arrays will likely go away eventually, but until it does, those are your options. But at least now it warns you. Previously, it just silently used the sort property, which does the wrong thing for arrays of char or wchar. - Jonathan M Davis
Mar 14 2016
On Monday, March 14, 2016 11:27:30 Ali Çehreli via Digitalmars-d-learn wrote:On 03/14/2016 06:56 AM, Jonathan M Davis via Digitalmars-d-learn wrote:wrote:On Monday, March 14, 2016 04:14:26 Ali Çehreli via Digitalmars-d-learnIt was my understanding that the built-in sort did indeed sort individual chars, so if that's not currently the case, I expect that someone fixed it at some point. Still, it should be removed from the language at some point. - Jonathan M DavisDo you mean property sort would sort individual chars? However, the following program indicates that it may have been fixed (i.e. made Unicode-aware):On 03/14/2016 04:01 AM, Jerry wrote: > I have a small problem with using UCS when sorting arrays. This pops > a > warning telling me to use the algorithm sort instead of the property > sort. Which I understand why it works that way. However that means I > can > not have syntactic sugar. So is there any way around this or do I > just > have to live with it? Two options: a) Use parentheses after sort: arr.sort() b) Import sort() under a different name: import std.algorithm: algsort = sort; arr.algsortYep. The sort property on arrays will likely go away eventually, but until it does, those are your options. But at least now it warns you. Previously, it just silently used the sort property, which does the wrong thing for arrays of char or wchar. - Jonathan M Davis
Mar 14 2016