Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
November 20, 2014 Clock.currTime | ||||
---|---|---|---|---|
| ||||
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? |
November 20, 2014 Re: Clock.currTime | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kent | 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
|
November 20, 2014 Re: Clock.currTime | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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.
|
November 20, 2014 Re: Clock.currTime | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kent | 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.
|
November 20, 2014 Re: Clock.currTime | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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);
}
|
November 20, 2014 Re: Clock.currTime | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kent | 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. |
November 20, 2014 Re: Clock.currTime | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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.
|
Copyright © 1999-2021 by the D Language Foundation