Re: toLower

2023-08-18 Thread Nick Treleaven via Digitalmars-d-learn
On Thursday, 17 August 2023 at 09:28:05 UTC, Joel wrote: .map!(std.uni.toLower) .sort!"aonlineapp.d(8): Error: none of the overloads of template `std.algorithm.sorting.sort` are callable using argument types `!("a

Re: toLower

2023-08-17 Thread Joel via Digitalmars-d-learn
On Thursday, 17 August 2023 at 14:14:00 UTC, bachmeier wrote: On Thursday, 17 August 2023 at 09:28:05 UTC, Joel wrote: I get an compile time error with sort after using toLower, putting in array before sort, didn’t work: ```d void main() { Import std; "Ezra

Re: toLower

2023-08-17 Thread bachmeier via Digitalmars-d-learn
On Thursday, 17 August 2023 at 09:28:05 UTC, Joel wrote: I get an compile time error with sort after using toLower, putting in array before sort, didn’t work: ```d void main() { Import std; "EzraTezla" .to!(char[]) .byCodeUnit

Re: toLower

2023-08-17 Thread Joel via Digitalmars-d-learn
the two `toLower` functions.. How do I get it to work? I tried std.ascii.toLower. And using alias toLower=std.ascii.toLower; To elaborate more, `toLower` doesn't work because function-scope aliases are not considered for UFCS. ``` alias toLower = std.ascii.toLower; ... // So

Re: toLower

2023-08-15 Thread FeepingCreature via Digitalmars-d-learn
On Tuesday, 15 August 2023 at 20:09:28 UTC, Joel wrote: On Tuesday, 15 August 2023 at 16:54:49 UTC, FeepingCreature wrote: But does *not* import `std.ascii`! So there's no ambiguity inside the `sort` string expression between the two `toLower` functions.. How do I get it to work? I tried

Re: toLower

2023-08-15 Thread bachmeier via Digitalmars-d-learn
, these modules are imported for use in string expressions: ``` import std.algorithm, std.conv, std.exception, std.math, std.range, std.string; import std.meta, std.traits, std.typecons; ``` And `std.string` itself publically imports: ``` public import std.uni : icmp, toLower, toLowerInPlace

Re: toLower

2023-08-15 Thread Joel via Digitalmars-d-learn
expressions: ``` import std.algorithm, std.conv, std.exception, std.math, std.range, std.string; import std.meta, std.traits, std.typecons; ``` And `std.string` itself publically imports: ``` public import std.uni : icmp, toLower, toLowerInPlace, toUpper, toUpperInPlace; ``` But does *not* import

Re: toLower

2023-08-15 Thread ryuukk_ via Digitalmars-d-learn
On Tuesday, 15 August 2023 at 16:47:36 UTC, Joel wrote: How come toLower works in the sort quotes, but not in the map? ```d void main() { import std; "EzraTezla" .to!(char[]) .byCodeUnit .sort!"a.toLower c.toLower) .writeln; } ``` onlinea

Re: toLower

2023-08-15 Thread FeepingCreature via Digitalmars-d-learn
On Tuesday, 15 August 2023 at 16:47:36 UTC, Joel wrote: How come toLower works in the sort quotes, but not in the map? ```d void main() { import std; "EzraTezla" .to!(char[]) .byCodeUnit .sort!"a.toLower c.toLower) .writeln; } ``` When yo

toLower

2023-08-15 Thread Joel via Digitalmars-d-learn
How come toLower works in the sort quotes, but not in the map? ```d void main() { import std; "EzraTezla" .to!(char[]) .byCodeUnit .sort!"a.toLower c.toLower) .writeln; } ``` onlineapp.d(60): Error: `toLower` matches conflicting symbols: /

Re: Inplace toLower()

2017-03-20 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-03-19 22:32, Nordlöw wrote: Is there an in-place version of std.uni.toLower() If not, how do I most elegantly construct one? I would recommend against toLower and toUpper as in-place versions. Not all letters can be converted in-place, i.e. they might require more storage

Re: Inplace toLower()

2017-03-19 Thread ag0aep6g via Digitalmars-d-learn
On 03/19/2017 10:32 PM, Nordlöw wrote: Is there an in-place version of std.uni.toLower() toLowerInPlace

Inplace toLower()

2017-03-19 Thread Nordlöw via Digitalmars-d-learn
Is there an in-place version of std.uni.toLower() If not, how do I most elegantly construct one?

Difference between toLower() and asLowerCase() for strings?

2016-01-24 Thread Jon D via Digitalmars-d-learn
I'm trying to identify the preferred ways to lower case a string. In std.uni there are two functions that return the lower case form of a string: toLower() and asLowerCase(). There is also toLowerInPlace(). I'm having trouble figuring out what the relationship is between these, and when

Re: Difference between toLower() and asLowerCase() for strings?

2016-01-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 24 January 2016 at 20:56:20 UTC, Jon D wrote: I'm trying to identify the preferred ways to lower case a string. In std.uni there are two functions that return the lower case form of a string: toLower() and asLowerCase(). There is also toLowerInPlace(). toLower will allocate a new

Re: Difference between toLower() and asLowerCase() for strings?

2016-01-24 Thread Jon D via Digitalmars-d-learn
On Sunday, 24 January 2016 at 21:04:46 UTC, Adam D. Ruppe wrote: On Sunday, 24 January 2016 at 20:56:20 UTC, Jon D wrote: I'm trying to identify the preferred ways to lower case a string. In std.uni there are two functions that return the lower case form of a string: toLower() and asLowerCase

Re: CTFE toUpper/toLower

2012-08-30 Thread cal
On Thursday, 30 August 2012 at 05:26:52 UTC, Philippe Sigaud wrote: And with no UFCS ? Did you try s ~= toUpper(field) ~ , ; Yeah with or without UFCS, the second one fails.

Re: CTFE toUpper/toLower

2012-08-30 Thread Jacob Carlborg
On 2012-08-30 02:13, cal wrote: Given this code for CTFE on a string array: enum E {one, two} enum string[] fields = [EnumMembers!E].to!(string[]); string print(string[] fields) { string s; foreach(string field; fields) { s ~= field.toUpper ~ , ; } return s; }

Re: CTFE toUpper/toLower

2012-08-30 Thread Jacob Carlborg
On 2012-08-30 08:28, Jacob Carlborg wrote: It works for me. DMD 2.060 Mac OS X. Oh, it does not. If I replace: enum string[] fields = [EnumMembers!E].to!(string[]); With: enum string[] fields = [one, two]; It works. -- /Jacob Carlborg

Re: CTFE toUpper/toLower

2012-08-30 Thread cal
On Thursday, 30 August 2012 at 06:30:50 UTC, Jacob Carlborg wrote: On 2012-08-30 08:28, Jacob Carlborg wrote: It works for me. DMD 2.060 Mac OS X. Oh, it does not. If I replace: enum string[] fields = [EnumMembers!E].to!(string[]); With: enum string[] fields = [one, two]; It works.

Re: CTFE toUpper/toLower

2012-08-30 Thread cal
On Thursday, 30 August 2012 at 17:38:48 UTC, cal wrote: On Thursday, 30 August 2012 at 06:30:50 UTC, Jacob Carlborg wrote: Replacing string[] with dstring[] for EnumMembers triggers a DMD bug, so I guess the CTFE interpreter is buggy even in the string[] case. Filed

CTFE toUpper/toLower

2012-08-29 Thread cal
Given this code for CTFE on a string array: enum E {one, two} enum string[] fields = [EnumMembers!E].to!(string[]); string print(string[] fields) { string s; foreach(string field; fields) { s ~= field.toUpper ~ , ; } return s; } pragma(msg, print([one, two]));

Re: CTFE toUpper/toLower

2012-08-29 Thread Philippe Sigaud
On Thu, Aug 30, 2012 at 2:13 AM, cal callumena...@gmail.com wrote: Given this code for CTFE on a string array: enum E {one, two} enum string[] fields = [EnumMembers!E].to!(string[]); string print(string[] fields) { string s; foreach(string field; fields) { s ~=

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-26 Thread Marco Leise
Am Sun, 22 Apr 2012 09:23:45 +0200 schrieb Jay Norwood j...@prismnet.com: On Sunday, 22 April 2012 at 06:26:42 UTC, Jonathan M Davis wrote: You can look at the code. It checks each of the characters in place. Unlike toLower, it doesn't need to generate a new string. But as far

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-24 Thread Regan Heath
On Mon, 23 Apr 2012 16:43:20 +0100, Steven Schveighoffer schvei...@yahoo.com wrote: While dealing with unicode in my std.stream rewrite, I've found that hand-decoding dchars is way faster than using library calls. After watching Andrei's talk on generic and generative programming I have

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-24 Thread Steven Schveighoffer
, by doing a byte comparison (no dchar decoding) until it finds a difference. That might be a huge speedup. Right now, all dchars are being decoded, and translated to the toLower counterpart. It may have an opposite effect, however, if there are a lot of strings that are equivalent when

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-24 Thread Steven Schveighoffer
On Tuesday, 24 April 2012 at 14:54:48 UTC, Steven Schveighoffer wrote: On Tuesday, 24 April 2012 at 11:24:44 UTC, Regan Heath wrote: After watching Andrei's talk on generic and generative programming I have to ask, which routines are you avoiding .. it seems we need to make them as good as the

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-24 Thread Jonathan M Davis
On Tuesday, April 24, 2012 12:24:44 Regan Heath wrote: On Mon, 23 Apr 2012 16:43:20 +0100, Steven Schveighoffer schvei...@yahoo.com wrote: While dealing with unicode in my std.stream rewrite, I've found that hand-decoding dchars is way faster than using library calls. After watching

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-23 Thread Steven Schveighoffer
On Sat, 21 Apr 2012 19:24:56 -0400, Jay Norwood j...@prismnet.com wrote: While playing with sorting the unzip archive entries I tried use of the last example in http://dlang.org/phobos/std_algorithm.html#sort std.algorithm.sort!(toLower(a.name) toLower(b.name

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-23 Thread Jay Norwood
On Monday, 23 April 2012 at 11:27:40 UTC, Steven Schveighoffer wrote: I think using std.string.icmp is the best solution. I would expect it to outperform even schwartz sort. -Steve icmp took longer... added about 1 sec vs 0.3 sec (for schwartzSort ) to the program execution time. bool

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-23 Thread Steven Schveighoffer
On Mon, 23 Apr 2012 09:49:50 -0400, Jay Norwood j...@prismnet.com wrote: On Monday, 23 April 2012 at 11:27:40 UTC, Steven Schveighoffer wrote: I think using std.string.icmp is the best solution. I would expect it to outperform even schwartz sort. -Steve icmp took longer... added about 1

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-22 Thread Jay Norwood
On Sunday, 22 April 2012 at 02:29:45 UTC, Jonathan M Davis wrote: Regardless of whether it's the Big(O) complexity or the constant factor that's the problem here, clearly there's enough additional overhead that it's causing problems for Jay's particular case. It's also the sort of thing that

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-22 Thread Jonathan M Davis
://dlang.org/phobos/std_string.html#icmp Technically, icmp(r1, r2) is equivalent to cmp!std.uni.toLower(a) std.uni.toLower(b)(r1, r2). You can look at the code. It checks each of the characters in place. Unlike toLower, it doesn't need to generate a new string. But as far as the comparison goes

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-22 Thread Jay Norwood
On Sunday, 22 April 2012 at 06:26:42 UTC, Jonathan M Davis wrote: You can look at the code. It checks each of the characters in place. Unlike toLower, it doesn't need to generate a new string. But as far as the comparison goes, they're the same - hence that line in the docs. - Jonathan M

Re: toLower() and Unicode are incomplete was: Re: avoid toLower in std.algorithm.sort compare alias

2012-04-22 Thread Dmitry Olshansky
On 22.04.2012 5:43, Ali Çehreli wrote: On 04/21/2012 04:24 PM, Jay Norwood wrote: While playing with sorting the unzip archive entries I tried use of the last example in http://dlang.org/phobos/std_algorithm.html#sort std.algorithm.sort!(toLower(a.name) toLower(b.name

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-22 Thread Jacob Carlborg
On 2012-04-22 01:24, Jay Norwood wrote: While playing with sorting the unzip archive entries I tried use of the last example in http://dlang.org/phobos/std_algorithm.html#sort std.algorithm.sort!(toLower(a.name) toLower(b.name),std.algorithm.SwapStrategy.stable)(entries); It was terribly slow

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-22 Thread SomeDude
On Saturday, 21 April 2012 at 23:24:57 UTC, Jay Norwood wrote: While playing with sorting the unzip archive entries I tried use of the last example in http://dlang.org/phobos/std_algorithm.html#sort std.algorithm.sort!(toLower(a.name) toLower(b.name),std.algorithm.SwapStrategy.stable

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-22 Thread Jay Norwood
On Sunday, 22 April 2012 at 00:36:19 UTC, bearophile wrote: Performing the toLower every time the cmp function is called doesn't change the O complexity. In Phobos there is an alternative sorting (Schwartzian sorting routime) that applies a function to each item before sorting them, usually

avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread Jay Norwood
While playing with sorting the unzip archive entries I tried use of the last example in http://dlang.org/phobos/std_algorithm.html#sort std.algorithm.sort!(toLower(a.name) toLower(b.name),std.algorithm.SwapStrategy.stable)(entries); It was terribly slow for sorting the 34k entries in my

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread Jonathan M Davis
On Sunday, April 22, 2012 01:24:56 Jay Norwood wrote: While playing with sorting the unzip archive entries I tried use of the last example in http://dlang.org/phobos/std_algorithm.html#sort std.algorithm.sort!(toLower(a.name) toLower(b.name),std.algorithm.SwapStrategy.stable)(entries

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread Jonathan M Davis
not sure how much more expensive - it might cost less than sort such that it actually doesn't matter as for as Big(O) goes though). Performing the toLower every time the cmp function is called doesn't change the O complexity. Yes it does. It adds a loop to each comparison (two loops

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread H. S. Teoh
the conversion only once is still more expensive than not converting, but I'm not sure how much more expensive - it might cost less than sort such that it actually doesn't matter as for as Big(O) goes though). Performing the toLower every time the cmp function is called doesn't change the O

toLower() and Unicode are incomplete was: Re: avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread Ali Çehreli
On 04/21/2012 04:24 PM, Jay Norwood wrote: While playing with sorting the unzip archive entries I tried use of the last example in http://dlang.org/phobos/std_algorithm.html#sort std.algorithm.sort!(toLower(a.name) toLower(b.name),std.algorithm.SwapStrategy.stable)(entries); Stealing

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread Jay Norwood
On Saturday, 21 April 2012 at 23:54:26 UTC, Jonathan M Davis wrote: Yeah. toLower would be called on both strings on _every_ compare. And since that involves a loop, that would make the overall call to sort an order of magnitude worse than if you didn't call toLower at all. I'm not sure

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread Jonathan M Davis
On Sunday, April 22, 2012 03:47:30 Jay Norwood wrote: On Saturday, 21 April 2012 at 23:54:26 UTC, Jonathan M Davis wrote: Yeah. toLower would be called on both strings on _every_ compare. And since that involves a loop, that would make the overall call to sort an order of magnitude

Re: toLower() and Unicode are incomplete was: Re: avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread Jonathan M Davis
On Saturday, April 21, 2012 18:43:23 Ali Çehreli wrote: On 04/21/2012 04:24 PM, Jay Norwood wrote: While playing with sorting the unzip archive entries I tried use of the last example in http://dlang.org/phobos/std_algorithm.html#sort std.algorithm.sort!(toLower(a.name) toLower

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread Jonathan M Davis
On Saturday, April 21, 2012 18:26:42 H. S. Teoh wrote: Actually, I don't think the nested loops affect Big-O complexity at all. The O(l) complexity (where l = string length) is already inherent in the string comparison str otherStr. Adding more loops over the strings doesn't change the Big-O