www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Clock.currTime

reply "Kent" <377737241 qq.com> writes:
I am reading the book 《D Cookbook》
In Page 36,this code can't be complied:

auto filtered =  filter!((a) => Clock.currTime() -
a.timeLastModified >> 14.days)(sorted);

"sorted"'s type is DirEntry[].

The errors :
Error	1	Error:
'currTime(cast(immutable(TimeZone))opCall()).opBinary(a.timeLastModified())'
is not of integral type, it is a Duration	

I don't know what's the problem?
Nov 20 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Kent:

 I am reading the book 《D Cookbook》
 In Page 36,this code can't be complied:

 auto filtered =  filter!((a) => Clock.currTime() -
 a.timeLastModified >> 14.days)(sorted);
Perhaps: mySorted.filter!(a => Clock.currTime - a.timeLastModified > 14.days); Bye, bearophile
Nov 20 2014
parent reply "Kent" <377737241 qq.com> writes:
On Thursday, 20 November 2014 at 15:31:28 UTC, bearophile wrote:
 Kent:

 I am reading the book 《D Cookbook》
 In Page 36,this code can't be complied:

 auto filtered =  filter!((a) => Clock.currTime() -
 a.timeLastModified >> 14.days)(sorted);
Perhaps: mySorted.filter!(a => Clock.currTime - a.timeLastModified > 14.days); Bye, bearophile
Thank you for your reply. But it still doesn't work.
Nov 20 2014
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Thursday, 20 November 2014 at 15:33:37 UTC, Kent wrote:
 mySorted.filter!(a => Clock.currTime - a.timeLastModified > 
 14.days);
Thank you for your reply. But it still doesn't work.
Are you sure you saw the important difference? There was a >> in the first post and it should be >. There's a few times throughout chapter one and two of the book where some symbols got messed up in the editing process and not fixed by the final draft. This looks like one of them.
Nov 20 2014
parent reply "Kent" <377737241 qq.com> writes:
On Thursday, 20 November 2014 at 15:38:10 UTC, Adam D. Ruppe
wrote:
 On Thursday, 20 November 2014 at 15:33:37 UTC, Kent wrote:
 mySorted.filter!(a => Clock.currTime - a.timeLastModified > 
 14.days);
Thank you for your reply. But it still doesn't work.
Are you sure you saw the important difference? There was a >> in the first post and it should be >. There's a few times throughout chapter one and two of the book where some symbols got messed up in the editing process and not fixed by the final draft. This looks like one of them.
I have notice the difference.Changed the ">>" to ">". void main(string[] argv) { import std.file, std.algorithm, std.datetime, std.range,std.stdio; DirEntry[] allFiles; foreach(DirEntry entry; dirEntries("E:/TDDOWNLOAD", SpanMode.depth)) allFiles ~= entry; auto sorted = sort!((a,b) => a.size > b.size)(allFiles); auto filtered = filter!(a => Clock.currTime() - a.timeLastModified > 14.days)(sorted); foreach(file; filtered.take!(10)) writeln(fiel.name); }
Nov 20 2014
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Thursday, 20 November 2014 at 15:45:55 UTC, Kent wrote:
     foreach(file; filtered.take!(10))
Oh, there shouldn't be a ! there either. Should be take(10), not take!(10). That's my mistake too...
         writeln(fiel.name);
also file is misspelled.
Nov 20 2014
parent "Kent" <377737241 qq.com> writes:
On Thursday, 20 November 2014 at 15:56:34 UTC, Adam D. Ruppe
wrote:
 On Thursday, 20 November 2014 at 15:45:55 UTC, Kent wrote:
    foreach(file; filtered.take!(10))
Oh, there shouldn't be a ! there either. Should be take(10), not take!(10). That's my mistake too...
        writeln(fiel.name);
also file is misspelled.
Thank you very much for help me. I notice another problem: foreach(file; filtered.take!(10)){...} This line has errors.I read the stdlib reference, and change the line to: foreach(file; take(filtered, 10)){...} It becomes right. Thank you again.
Nov 20 2014