Re: std.algorithm

2017-11-30 Thread flamencofantasy via Digitalmars-d-learn
On Thursday, 30 November 2017 at 21:49:56 UTC, Meta wrote: On Thursday, 30 November 2017 at 20:49:36 UTC, flamencofantasy wrote: [...] This *almost* works: [...] That's what I needed, thanks!

Re: std.algorithm

2017-11-30 Thread Meta via Digitalmars-d-learn
On Thursday, 30 November 2017 at 20:49:36 UTC, flamencofantasy wrote: Hello, I have the following csv text; auto input = "Start Date,End Date,Subject,All day event,Categories,Show time as 1/1/2018,1/1/2018,New Year's Day,TRUE,Holiday,3 1/15/2018,1/15/2018,\"Martin Luther King, Jr.

Re: std.algorithm can not be used inside pure functions?

2017-05-06 Thread Szabo Bogdan via Digitalmars-d-learn
On Saturday, 6 May 2017 at 15:01:16 UTC, Adam D. Ruppe wrote: On Saturday, 6 May 2017 at 14:14:41 UTC, Szabo Bogdan wrote: oh yes, I get it... begin and end are `SysTime`.. there is any workaround for this? Don't use pure? I don't think any of the SysTime conversion methods are pure since

Re: std.algorithm can not be used inside pure functions?

2017-05-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, May 6, 2017 2:14:41 PM CEST Szabo Bogdan via Digitalmars-d- learn wrote: > On Saturday, 6 May 2017 at 13:21:10 UTC, Adam D. Ruppe wrote: > > On Saturday, 6 May 2017 at 13:19:17 UTC, Szabo Bogdan wrote: > >> a.begin.toISOExtString, > > > > I believe that function is not marked pure if

Re: std.algorithm can not be used inside pure functions?

2017-05-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 6 May 2017 at 14:14:41 UTC, Szabo Bogdan wrote: oh yes, I get it... begin and end are `SysTime`.. there is any workaround for this? Don't use pure? I don't think any of the SysTime conversion methods are pure since all of them call C functions which pull from the time zone...

Re: std.algorithm can not be used inside pure functions?

2017-05-06 Thread Szabo Bogdan via Digitalmars-d-learn
On Saturday, 6 May 2017 at 13:21:10 UTC, Adam D. Ruppe wrote: On Saturday, 6 May 2017 at 13:19:17 UTC, Szabo Bogdan wrote: a.begin.toISOExtString, I believe that function is not marked pure if it is a SysTime because it needs to pull global timezone info. What is the type of a.begin? oh

Re: std.algorithm each documentation terse

2015-07-20 Thread John Colvin via Digitalmars-d-learn
On Monday, 20 July 2015 at 14:40:59 UTC, jmh530 wrote: I have found the documentation for each in std.algorithm a bit terse. It seemed like it was an eager version of map, but it seems to be a bit more limited than that. In particular, the documentation says that if you can mutate the value

Re: std.algorithm each documentation terse

2015-07-20 Thread jmh530 via Digitalmars-d-learn
On Monday, 20 July 2015 at 14:40:59 UTC, jmh530 wrote: Is there a way to write a void lambda that would work with each? Ugh, I hate that I can't edit posts. I meant to delete this line.

Re: std.algorithm each documentation terse

2015-07-20 Thread via Digitalmars-d-learn
On Monday, 20 July 2015 at 15:08:16 UTC, Nicholas Wilson wrote: But the lambda takes a ref parameter... Yes, but it never writes to it: x.each!((ref a) = a + 1); Instead, this should work: x.each!((ref a) = a = a + 1); ... as a short-hand for: x.each!((ref a) { a = a + 1; });

Re: std.algorithm each documentation terse

2015-07-20 Thread jmh530 via Digitalmars-d-learn
On Monday, 20 July 2015 at 15:12:28 UTC, Marc Schütz wrote: On Monday, 20 July 2015 at 15:08:16 UTC, Nicholas Wilson wrote: But the lambda takes a ref parameter... Yes, but it never writes to it: x.each!((ref a) = a + 1); Instead, this should work: x.each!((ref a) = a = a + 1);

Re: std.algorithm each documentation terse

2015-07-20 Thread Meta via Digitalmars-d-learn
On Monday, 20 July 2015 at 14:40:59 UTC, jmh530 wrote: I have found the documentation for each in std.algorithm a bit terse. It seemed like it was an eager version of map, but it seems to be a bit more limited than that. In particular, the documentation says that if you can mutate the value

Re: std.algorithm each documentation terse

2015-07-20 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 20 July 2015 at 14:59:21 UTC, John Colvin wrote: On Monday, 20 July 2015 at 14:40:59 UTC, jmh530 wrote: [...] Everything is exactly as I would expect. Lambdas with = are just shorthand that skips the return expression and std.algorithm.each just calls the lambda for each element

Re: std.algorithm each documentation terse

2015-07-20 Thread Jack Applegame via Digitalmars-d-learn
Also, map is lazy, but each isn't.

Re: std.algorithm each documentation terse

2015-07-20 Thread sigod via Digitalmars-d-learn
On Monday, 20 July 2015 at 14:40:59 UTC, jmh530 wrote: I have found the documentation for each in std.algorithm a bit terse. It seemed like it was an eager version of map, but it seems to be a bit more limited than that. Why are you trying to use `each` in place which belongs to `map`?

Re: std.algorithm each documentation terse

2015-07-20 Thread jmh530 via Digitalmars-d-learn
On Monday, 20 July 2015 at 21:24:37 UTC, sigod wrote: On Monday, 20 July 2015 at 14:40:59 UTC, jmh530 wrote: I have found the documentation for each in std.algorithm a bit terse. It seemed like it was an eager version of map, but it seems to be a bit more limited than that. Why are you

Re: std.algorithm sort() and reverse() confusion

2015-02-02 Thread bearophile via Digitalmars-d-learn
Jonathan M Davis: arr.reverse.map!sqrt Yes, but arguably, chaining calls in this case is bad, We have discussed this some time... and I'd like reverse() to return the original array (like the deprecated array .reverse property). It's not a perfect design, but allowing UFCS chains is

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread Kagamin via Digitalmars-d-learn
writeln(Sorted, reversed: , retro(sort(myVals))); ?

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread Paul via Digitalmars-d-learn
On Friday, 30 January 2015 at 16:21:24 UTC, Kagamin wrote: writeln(Sorted, reversed: , retro(sort(myVals))); ? Or... writeln(Reverse sorted: , sort!(a b)(vals)); but I still don't understand the original 'error'.

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread Tobias Pankrath via Digitalmars-d-learn
On Friday, 30 January 2015 at 17:07:17 UTC, Paul wrote: On Friday, 30 January 2015 at 16:21:24 UTC, Kagamin wrote: writeln(Sorted, reversed: , retro(sort(myVals))); ? Or... writeln(Reverse sorted: , sort!(a b)(vals)); but I still don't understand the original 'error'. Take a look at the

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, January 30, 2015 10:46:54 Ali Çehreli via Digitalmars-d-learn wrote: On 01/30/2015 09:55 AM, Jonathan M Davis via Digitalmars-d-learn wrote: there is no such benefit with reverse, so there's no need to return anything. Still, returning the original range would help with

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, January 30, 2015 18:42:57 FG via Digitalmars-d-learn wrote: On 2015-01-30 at 17:07, Paul wrote: writeln(Sorted, reversed: , reverse(myVals)); Gives me... Error: template std.stdio.writeln cannot deduce function from argument types !()(string, void) As it should, because

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread Paul via Digitalmars-d-learn
On Friday, 30 January 2015 at 18:46:55 UTC, Ali Çehreli wrote: there is no such benefit with reverse, so there's no need to return anything. Still, returning the original range would help with chaining calls: arr.reverse.map!sqrt Side note: There is the confusion between the .reverse

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread FG via Digitalmars-d-learn
On 2015-01-30 at 17:07, Paul wrote: writeln(Sorted, reversed: , reverse(myVals)); Gives me... Error: template std.stdio.writeln cannot deduce function from argument types !()(string, void) As it should, because reverse returns nothing, void. But you may wonder what the design choice behind

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread FG via Digitalmars-d-learn
On 2015-01-30 at 18:42, FG wrote: But you may wonder what the design choice behind that was that reverse doesn't return the range itself while sort does (a SortedRange, specifically). Although, after thinking about it, it makes sense. sort is used mostly to enforce that something is sorted

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread Ali Çehreli via Digitalmars-d-learn
On 01/30/2015 09:55 AM, Jonathan M Davis via Digitalmars-d-learn wrote: sort returns a different type rather than the original type, and that type indicates that its sorted, and some algoritms are able to take advantage of that. I covered that a little bit during DConf 2014, at around

Re: std.algorithm and templates

2014-12-10 Thread bearophile via Digitalmars-d-learn
meat: class Woah(){} class Bro: Woah{} DList!Woah woahs; and I'm having trouble with.. foreach( bro; woahs.filter!( a = cast(Bro)a !is null)) import std.algorithm, std.container; class Woah {} class Bro : Woah {} void main() { DList!Woah woahs; foreach (bro; woahs[].filter!(a =

Re: std.algorithm range violation

2014-05-28 Thread Wanderer via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 10:10:41 UTC, maarten van damme via Digitalmars-d-learn wrote: an anyone explain me what I'm doing wrong here : [code] dstring[][dstring] providor_symbol_map; ...

Re: std.algorithm range violation

2014-05-28 Thread maarten van damme via Digitalmars-d-learn
I'm trying to analyze the usage of certain words in a large number of spam emails, and I want for every interesting word a list of 'providors', that mentioned that word. with associative arrays I hoped to get it by using array[interestingworde]. And I have to refer outside from sort(x,y) as

Re: std.algorithm range violation

2014-05-28 Thread bearophile via Digitalmars-d-learn
maarten van damme: writeln(providor_symbol_map.keys.sort!((x,y)=providor_symbol_map[x].length=providor_symbol_map[y].length)); [/code] Try: ((x, y) = providor_symbol_map[x].length providor_symbol_map[y].length) Bye, bearophile

Re: std.algorithm range violation

2014-05-28 Thread Wanderer via Digitalmars-d-learn
Sorry about typo, I meant providor_symbol_map.sort!((x,y)={x.value.lengthy.value.length}) above.

Re: std.algorithm range violation

2014-05-28 Thread Wanderer via Digitalmars-d-learn
Aha, so you want to maintain spam word - set of senders relationship, so it's actually map of sets and your declaration is correct. You only need to sort map's entries (key and value pairs together). If D supports that, it should be something like

Re: std.algorithm range violation

2014-05-28 Thread bearophile via Digitalmars-d-learn
Wanderer: providor_symbol_map.sort!((x,y)={x.value.length=y.value.length}), This lambda doesn't return a boolean. Also, add spaces around operators and after commas. Bye, bearophile

Re: std.algorithm range violation

2014-05-28 Thread maarten van damme via Digitalmars-d-learn
wow. senpai, teach me what I did wrong... 2014-05-28 13:21 GMT+02:00 bearophile via Digitalmars-d-learn digitalmars-d-learn@puremagic.com: maarten van damme: writeln(providor_symbol_map.keys.sort!((x,y)=providor_ symbol_map[x].length=providor_symbol_map[y].length)); [/code] Try:

Re: std.algorithm range violation

2014-05-28 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 11:40:05 UTC, Wanderer wrote: Sorry about typo, I meant providor_symbol_map.sort!((x,y)={x.value.lengthy.value.length}) above. providor_symbol_map is an Associative Array, so you can't sort that. *Usually*, you want to do what the OP did, which is to get the

Re: std.algorithm range violation

2014-05-28 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 17:39:15 UTC, monarch_dodra wrote: On Wednesday, 28 May 2014 at 11:40:05 UTC, Wanderer wrote: Sorry about typo, I meant providor_symbol_map.sort!((x,y)={x.value.lengthy.value.length}) above. providor_symbol_map is an Associative Array, so you can't sort that.

Re: std.algorithm for changing array values

2014-01-15 Thread TheFlyingFiddle
On Wednesday, 15 January 2014 at 20:34:32 UTC, Andre wrote: Hi, I checked std.algorithm but have no glue which functions I can use to rewrite following code with some nice algorithm functions. I have an array of structs. I want to check for a specific key and if found I change the value. If it

Re: std.algorithm for changing array values

2014-01-15 Thread anonymous
On Wednesday, 15 January 2014 at 20:34:32 UTC, Andre wrote: Hi, I checked std.algorithm but have no glue which functions I can use to rewrite following code with some nice algorithm functions. I have an array of structs. I want to check for a specific key and if found I change the value. If it

Re: std.algorithm for changing array values

2014-01-15 Thread anonymous
On Wednesday, 15 January 2014 at 20:54:06 UTC, anonymous wrote: On Wednesday, 15 January 2014 at 20:34:32 UTC, Andre wrote: Hi, I checked std.algorithm but have no glue which functions I can use to rewrite following code with some nice algorithm functions. I have an array of structs. I want

Re: std.algorithm for changing array values

2014-01-15 Thread Kapps
On Wednesday, 15 January 2014 at 20:34:32 UTC, Andre wrote: foreach(entry;entries){ if (entry.key == 3){ entry.value = 42; found = true; } } One thing to keep in mind is that structs are passed by

Re: std.algorithm for changing array values

2014-01-15 Thread Meta
On Wednesday, 15 January 2014 at 20:34:32 UTC, Andre wrote: Hi, I checked std.algorithm but have no glue which functions I can use to rewrite following code with some nice algorithm functions. I have an array of structs. I want to check for a specific key and if found I change the value. If it

Re: std.algorithm for changing array values

2014-01-15 Thread bearophile
Kapps: One thing to keep in mind is that structs are passed by value, so this foreach would be operating on a copy of the entry. So your setting the value to 42 would have no effect. Instead you would need foreach(ref entry; entries) in order to have the change take effect (regardless of

Re: std.algorithm Map using a external variable

2012-12-10 Thread Jacob Carlborg
On 2012-12-10 19:21, Zardoz wrote: I'm trying to use Map with a code like this : ... immutable int m = 10; int[] caca = [1,2,3,4]; auto caca2 = map!( (a) {return a * m;})(caca); writeln(caca2); ... I get a Segmentation fault some times: The most interesting point it's that

Re: std.algorithm Map using a external variable

2012-12-10 Thread H. S. Teoh
On Mon, Dec 10, 2012 at 07:21:47PM +0100, Zardoz wrote: I'm trying to use Map with a code like this : ... immutable int m = 10; int[] caca = [1,2,3,4]; auto caca2 = map!( (a) {return a * m;})(caca); writeln(caca2); ... I get a Segmentation fault some times: The most

Re: std.algorithm Map using a external variable

2012-12-10 Thread Maxim Fomin
On Monday, 10 December 2012 at 18:21:48 UTC, Zardoz wrote: I'm trying to use Map with a code like this : ... immutable int m = 10; int[] caca = [1,2,3,4]; auto caca2 = map!( (a) {return a * m;})(caca); writeln(caca2); ... I get a Segmentation fault some times: The most interesting

Re: std.algorithm Map using a external variable

2012-12-10 Thread Zardoz
Well. I just try it again and I noticed this things : -Changind the lambda function from : auto caca2 = map!((a) {return a * iDeltaT;})(caca); to : auto caca2 = map!((a) {return a + iDeltaT;})(caca); Avoid the segmentation fault -Using dmd 2.60 avoid the segmentation fault. The source code