Re: How can I express the type '(int) = int' where it is a function or a delegate

2014-07-16 Thread Puming via Digitalmars-d-learn
On Wednesday, 16 July 2014 at 04:10:13 UTC, Rikki Cattermole wrote: On 16/07/2014 3:50 p.m., Puming wrote: I'd like to have a Command class, where their is a name and a handler field: ```d class Command { string name; string delegate(string[]) handler; } ``` this is ok, but sometimes I

Re: DUB git master hang

2014-07-16 Thread Sönke Ludwig via Digitalmars-d-learn
Am 15.07.2014 00:29, schrieb Nordlöw: On Monday, 14 July 2014 at 22:27:48 UTC, Nordlöw wrote: and then it hangs with same behaviour. It finally got through...hmm maybe I'm on a slow 3g-network currently... Although the log indicates that it hung while extracting the downloaded zip file.

md5 hashing acting strangly?

2014-07-16 Thread Sean Campbell via Digitalmars-d-learn
i have the following code char[] Etag(string file){ auto info = DirEntry(file); ubyte[16] hash = md5Of(to!string(info.timeLastAccessed.day)~ to!string(info.timeLastAccessed.month)~

Re: md5 hashing acting strangly?

2014-07-16 Thread bearophile via Digitalmars-d-learn
Sean Campbell: i have the following code char[] Etag(string file){ auto info = DirEntry(file); ubyte[16] hash = md5Of(to!string(info.timeLastAccessed.day)~ to!string(info.timeLastAccessed.month)~

Re: md5 hashing acting strangly?

2014-07-16 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 16 July 2014 at 12:15:34 UTC, bearophile wrote: Such kind of bugs are impossible in Rust. Hopefully we'll eventually remove them from D too. Seems like a popular issue. Is there a bug report for it?

Re: md5 hashing acting strangly?

2014-07-16 Thread bearophile via Digitalmars-d-learn
Kagamin: Seems like a popular issue. Y es, it is. Is there a bug report for it? Bug report for what? To ask for [] to be used when you slice a fixed size array? This is in Bugzilla. Or perhaps you are asking for lifetime management of the data? This is currently discussed in the main D

Re: md5 hashing acting strangly?

2014-07-16 Thread Kagamin via Digitalmars-d-learn
Report for the problem when a temporary fixed-size array is assigned to a slice, which is escaped.

Re: md5 hashing acting strangly?

2014-07-16 Thread bearophile via Digitalmars-d-learn
Kagamin: Report for the problem when a temporary fixed-size array is assigned to a slice, which is escaped. I think this is already in Bugzilla. But the point is: you can't solve this problem locally and with small means. You need a principled solution (or no solution at all, as now) of

Re: md5 hashing acting strangly?

2014-07-16 Thread Kagamin via Digitalmars-d-learn
I have a more pragmatic view. Do you know the issue number?

Re: md5 hashing acting strangly?

2014-07-16 Thread Kagamin via Digitalmars-d-learn
Aren't these your words: fixing as many errors as possible always helps even if we don't fix all errors?

Problem with trying sample from doc page

2014-07-16 Thread Pavel via Digitalmars-d-learn
Hi! I've been experimenting with D functions, and found this piece of code: // int abc(int delegate(long i)); int def(int function(long s)); void test() { int b = 3; abc( (long c) { return 6 + b; } ); // inferred to delegate def( (long c) { return c * 2; } ); // inferred to function }

Re: Problem with trying sample from doc page

2014-07-16 Thread Pavel via Digitalmars-d-learn
On Wednesday, 16 July 2014 at 15:12:58 UTC, Pavel wrote: Hi! I've been experimenting with D functions, and found this piece of code: // int abc(int delegate(long i)); int def(int function(long s)); void test() { int b = 3; abc( (long c) { return 6 + b; } ); // inferred to delegate def(

Re: Problem with trying sample from doc page

2014-07-16 Thread Adam D. Ruppe via Digitalmars-d-learn
I would just change all the longs to ints and it would probably work. Or all the longs to ints. It really should have been consistent in the docs, since the point of this is delegate vs function, not int vs long...

Re: Problem with trying sample from doc page

2014-07-16 Thread Brad Anderson via Digitalmars-d-learn
On Wednesday, 16 July 2014 at 15:44:03 UTC, Adam D. Ruppe wrote: I would just change all the longs to ints and it would probably work. Or all the longs to ints. It really should have been consistent in the docs, since the point of this is delegate vs function, not int vs long...

Re: How can I express the type '(int) = int' where it is a function or a delegate

2014-07-16 Thread Kagamin via Digitalmars-d-learn
The compiler would generate calls to toDelegate and toFunction automatically.

Re: md5 hashing acting strangly?

2014-07-16 Thread Ary Borenszweig via Digitalmars-d-learn
On 7/16/14, 10:22 AM, bearophile wrote: Kagamin: Report for the problem when a temporary fixed-size array is assigned to a slice, which is escaped. I think this is already in Bugzilla. But the point is: you can't solve this problem locally and with small means. You need a principled solution

Re: Converting a POD struct to a class at compile-time ?

2014-07-16 Thread bearophile via Digitalmars-d-learn
Klb: Hello, I'd like to know if it's possible, using CTFE, mixin etc to convert a POD struct to a class at compile time. I remember Andrei planned to add this small thingie to Phobos, but it's still missing. Bye, bearophile

Re: md5 hashing acting strangly?

2014-07-16 Thread bearophile via Digitalmars-d-learn
Ary Borenszweig: When assigning a fixed size array to a slice, can't you just allocate memory and copy the data there (I mean, let the compiler do that in that case)? That would be safe, right? Yes, using a .dup: char[] hashstring = toHexString(hash).dup; But the compiler should not do

Re: Converting a POD struct to a class at compile-time ?

2014-07-16 Thread Adam D. Ruppe via Digitalmars-d-learn
Not a direct answer, but the way I'd do this is to just use composition: class Foo { YourStruct _this; alias _this this; } boom, it'd work pretty well just like that...

Re: Converting a POD struct to a class at compile-time ?

2014-07-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 16 July 2014 at 17:43:03 UTC, Klb wrote: auto names = __traits(allMembers, S); Error: static variable _names_field_0 cannot be read at compile time. The problem there is names is a regular runtime variable and mixins need to use compile time stuff. If you make that enum

Re: Converting a POD struct to a class at compile-time ?

2014-07-16 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 16, 2014 at 06:07:32PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: Not a direct answer, but the way I'd do this is to just use composition: class Foo { YourStruct _this; alias _this this; } boom, it'd work pretty well just like that... +1, simple answer to

Re: md5 hashing acting strangly?

2014-07-16 Thread Ali Çehreli via Digitalmars-d-learn
On 07/16/2014 06:31 AM, Kagamin wrote: I have a more pragmatic view. Do you know the issue number? https://issues.dlang.org/show_bug.cgi?id=8838 Ali

Re: Converting a POD struct to a class at compile-time ?

2014-07-16 Thread Klb via Digitalmars-d-learn
On Wednesday, 16 July 2014 at 18:09:10 UTC, Adam D. Ruppe wrote: On Wednesday, 16 July 2014 at 17:43:03 UTC, Klb wrote: auto names = __traits(allMembers, S); Error: static variable _names_field_0 cannot be read at compile time. The problem there is names is a regular runtime variable

Re: Extended math library

2014-07-16 Thread Martijn Pot via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 22:09:43 UTC, ponce wrote: On Tuesday, 15 July 2014 at 20:46:32 UTC, Martijn Pot wrote: To make a long story short: Is there any math library with e.g. mean, std, polynomial fitting, ...? https://github.com/kyllingstad/scid https://github.com/dsimcha/dstats

Re: Extended math library

2014-07-16 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 16 July 2014 at 19:43:26 UTC, Martijn Pot wrote: On Tuesday, 15 July 2014 at 22:09:43 UTC, ponce wrote: On Tuesday, 15 July 2014 at 20:46:32 UTC, Martijn Pot wrote: To make a long story short: Is there any math library with e.g. mean, std, polynomial fitting, ...?

Re: Converting a POD struct to a class at compile-time ?

2014-07-16 Thread Rene Zwanenburg via Digitalmars-d-learn
On Wednesday, 16 July 2014 at 18:27:31 UTC, Klb wrote: On Wednesday, 16 July 2014 at 18:09:10 UTC, Adam D. Ruppe wrote: On Wednesday, 16 July 2014 at 17:43:03 UTC, Klb wrote: auto names = __traits(allMembers, S); Error: static variable _names_field_0 cannot be read at compile time. The

Re: Setting dates

2014-07-16 Thread Joel via Digitalmars-d-learn
On Monday, 14 July 2014 at 05:58:13 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: On Friday, July 11, 2014 04:01:24 Joel via Digitalmars-d-learn wrote: I've been trying to set a date for my program (a small struct): import std.datetime; auto date = cast(DateTime)Clock.currTime();

Re: Generating Strings with Random Contents

2014-07-16 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
Alternative: randomSample(lowercase, 10, lowercase.length).writeln; No, I don't think that's appropriate, because it will pick 10 individual characters from a, b, c, ... , z (i.e. no character will appear more than once), and the characters picked will appear in alphabetical order.

Re: Extended math library

2014-07-16 Thread ponce via Digitalmars-d-learn
On Wednesday, 16 July 2014 at 21:12:00 UTC, bachmeier wrote: Have you tried them? Do they work? I couldn't get scid to work last year. I've never heard of dstats before, but it hasn't seen any activity in two years. I'd be surprised if it worked with the latest release of DMD. Can't speak

GC.realloc() fails to initialize some part of the memory

2014-07-16 Thread Ali Çehreli via Digitalmars-d-learn
Here is an interesting case related to an undocumented feature of GC.realloc(). Although I think there is a bug, I don't want to create a bug report yet because the feature is not even documented. :) First, here is its most recent definition from druntime/src/gc/gc.d: void *realloc(void