Re: Get current date and time with std.datetime

2011-10-06 Thread Jonathan M Davis
On Thursday, October 06, 2011 23:31:26 Jonathan M Davis wrote:
> On Friday, October 07, 2011 08:23:10 Jacob Carlborg wrote:
> > On 2011-10-07 08:15, Jonathan M Davis wrote:
> > > On Friday, October 07, 2011 19:08:33 Joel Christensen wrote:
> > >> Hi,
> > >> 
> > >> I have a program that uses the old time stuff before the module
> > >> std.datetime. I have a DateTime object, but I can't seem to set
> > >> its
> > >> properties to the current time.
> > >> 
> > >> Some thing like:
> > >> DateTime dateTime;
> > >> dateTime = getCurrentDateTime();
> > > 
> > > http://d-programming-language.org/intro-to-datetime.html
> > 
> > May I suggest that you put an example on top of that article that gets
> > the current date and time.
> 
> It's already in the documentation at the top of the module. What I need to
> do is put a link to the article in that documetantion.

I just added a link to the article to std.datetime, so it'll be there starting 
with the next release. What I'd _really_ like to see fixed though is the 
anchor-generation with ddoc so that I can actually properly organize the links 
at the top of std.datetime.

- Jonathan M Davis


Re: Get current date and time with std.datetime

2011-10-06 Thread Jonathan M Davis
On Friday, October 07, 2011 08:23:10 Jacob Carlborg wrote:
> On 2011-10-07 08:15, Jonathan M Davis wrote:
> > On Friday, October 07, 2011 19:08:33 Joel Christensen wrote:
> >> Hi,
> >> 
> >> I have a program that uses the old time stuff before the module
> >> std.datetime. I have a DateTime object, but I can't seem to set its
> >> properties to the current time.
> >> 
> >> Some thing like:
> >> DateTime dateTime;
> >> dateTime = getCurrentDateTime();
> > 
> > http://d-programming-language.org/intro-to-datetime.html
> 
> May I suggest that you put an example on top of that article that gets
> the current date and time.

It's already in the documentation at the top of the module. What I need to do 
is put a link to the article in that documetantion.

- Jonathan M Davis


Re: Get current date and time with std.datetime

2011-10-06 Thread Jacob Carlborg

On 2011-10-07 08:15, Jonathan M Davis wrote:

On Friday, October 07, 2011 19:08:33 Joel Christensen wrote:

Hi,

I have a program that uses the old time stuff before the module
std.datetime. I have a DateTime object, but I can't seem to set its
properties to the current time.

Some thing like:
DateTime dateTime;
dateTime = getCurrentDateTime();


http://d-programming-language.org/intro-to-datetime.html


May I suggest that you put an example on top of that article that gets 
the current date and time.


--
/Jacob Carlborg


Re: Get current date and time with std.datetime

2011-10-06 Thread Jonathan M Davis
On Friday, October 07, 2011 19:08:33 Joel Christensen wrote:
> Hi,
> 
> I have a program that uses the old time stuff before the module
> std.datetime. I have a DateTime object, but I can't seem to set its
> properties to the current time.
> 
> Some thing like:
> DateTime dateTime;
> dateTime = getCurrentDateTime();

http://d-programming-language.org/intro-to-datetime.html


Get current date and time with std.datetime

2011-10-06 Thread Joel Christensen

Hi,

I have a program that uses the old time stuff before the module 
std.datetime. I have a DateTime object, but I can't seem to set its 
properties to the current time.


Some thing like:
DateTime dateTime;
dateTime = getCurrentDateTime();

-JoelCNZ


Re: Stack Overflow error missing

2011-10-06 Thread Jonathan M Davis
On Friday, October 07, 2011 05:28:39 Andrej Mitrovic wrote:
> I'm fairly sure this used to give me a stack overflow error:
> void test() {
> test();
> }
> 
> void main() {
> test();
> }
> 
> Now it only returns exit code -1073741819.
> 
> Could this be related to how WinXP managers error reporting? It's
> possible that I have some error reporting service disabled, but I'll
> have to check. Is anyone else getting just the exit code?

On Linux, I'm getting a segmentation fault, the same as I always have gotten 
when the stack gets blown. So, this does appear to be a Windows-specific issue.

- Jonathan M Davis


Stack Overflow error missing

2011-10-06 Thread Andrej Mitrovic
I'm fairly sure this used to give me a stack overflow error:
void test() {
test();
}

void main() {
test();
}

Now it only returns exit code -1073741819.

Could this be related to how WinXP managers error reporting? It's
possible that I have some error reporting service disabled, but I'll
have to check. Is anyone else getting just the exit code?


Re: Implicit cast to immutable

2011-10-06 Thread Steven Schveighoffer
On Wed, 05 Oct 2011 19:19:37 -0400, bearophile   
wrote:



Do you know why this program doesn't compile (with DMD 2.056head)?


immutable(int[]) foo(in int[] x) pure {
return new int[1];
}
void main() {}


It gives:
test.d(2): Error: cannot implicitly convert expression (new int[](1u))  
of type int[] to immutable(int[])


This program instead compiles (now x is int[2] instead of int[]):

immutable(int[]) foo(in int[2] x) pure {
return new int[1];
}
void main() {}


I think it's a bug.

new should be considered pure, and since it's return value cannot be a  
reference to any parameter, it should implicitly cast to immutable.


The fact that changing the parameter to foo makes it compile is a big clue.

Note, this should compile even if foo isn't pure, since new is pure (no  
matter what type of function it is in).


-Steve


Re: Implicit cast to immutable

2011-10-06 Thread bearophile
Christophe:

> That is very consistent, so I don't think this 
> should be considered as a bug. There may be an improvement to ask to 
> make the compiler able to check when the cast to immutable is safe, but 
> I don't think there is a bug.

The compiler already performs such checks, in this case it answers "no" and I 
don't understand why, I think it's not the right answer.


> You would need to have pure delegates to have a real effect, wouldn't 
> you ?

The compiler is already able to infer delegate purity, I think.

Bye,
bearophile


Re: Implicit cast to immutable

2011-10-06 Thread Christophe
bearophile , dans le message (digitalmars.D.learn:29961), a écrit :
> Andrej Mitrovic:
> 
>> Maybe:
>> 
>> immutable(int[]) foo(in int[] x) pure {
>>return new immutable(int[1]);
>> }
>> 
>> void main() {}
> 
> I'd like to know why the code in my original post doesn't compile. I suspect 
> it's a DMD bug, but I am not sure.

The error message tells you why. new int[1] is not castable to immutable 
int[] (in a pure function). The solution is to change new int[1] to make 
it immutable directly. That is very consistent, so I don't think this 
should be considered as a bug. There may be an improvement to ask to 
make the compiler able to check when the cast to immutable is safe, but 
I don't think there is a bug.

>> Or does this have something to do with implicit casts to immutable for
>> pure functions?
> 
> Right.
> 
> 
>> I'm only vaguely familiar with pure..
> 
> I suggest you to use purity more and more in D, because it helps and 
> with the recent bug fixes it is also becoming usable in D (but there 
> are some significant problems left, example: map/filter are not pure 
> yet).

You would need to have pure delegates to have a real effect, wouldn't 
you ?

-- 
Christophe