Re: Meaning of const

2012-01-24 Thread bearophile
Jonathan M Davis: > Now, the confusing part is the fact that unlike C++, D allows you to put the > const for making the function on the _left-hand_ side of the function (C++ > only lets you put it on the right). This is to increase consistency between > modifers (public, override, pure, etc.) -

Re: Meaning of const

2012-01-24 Thread H. S. Teoh
On Tue, Jan 24, 2012 at 07:06:47PM -0500, Jonathan M Davis wrote: [...] > So, while a C++ programmer expects that > > int f2() const > > means that f2 is const, they're likely to be surprised by the fact that in > > const int f1() > > it's the int that's const, not f1. [...] Wait, I thought 'c

Re: KeyType, ValueType traits for hashes

2012-01-24 Thread Andrej Mitrovic
Unfortunately you would have to do that with every template in order to be consistent, and that's too much work. The real improvement would be for the compiler to let us know *which* of the constraints failed, e.g.: alias KeyType!(int[]) Key; Error: Can't instantiate KeyType!(int) due to failed c

Re: Meaning of const

2012-01-24 Thread Ali Çehreli
On 01/24/2012 04:06 PM, Jonathan M Davis wrote: >> class A { >> int x; >> >> const int f1() { ... } >> int f2() const { ... } >> const(int) f3() { ... } >> } >> [...] > int f2() const > > becomes > > int f2(const A this) > > Now, the confusing part is the fact that unlike C++, D allows you to

Re: foreach with classes like associative array?

2012-01-24 Thread Steven Schveighoffer
On Fri, 20 Jan 2012 19:53:33 -0500, Matt Soucy wrote: So I was messing around with some code I've been writing today, and I wanted to use a foreach for something, as if it were an associative array. The problem is, I can't find any information on how to do that. I can't use something like "a

Re: floating-WTF - Compiler-BUG with 64bit

2012-01-24 Thread Timon Gehr
On 01/24/2012 10:28 PM, %u wrote: Shouldn't this go into 'digitalmars.D' ? It should go straight to the bug tracker.

Re: Meaning of const

2012-01-24 Thread Jonathan M Davis
On Tuesday, January 24, 2012 15:52:50 H. S. Teoh wrote: > Hi all, > > I'm a bit confused by what 'const' means when used as part of a member > function's signature: > > class A { > int x; > > const int f1() { ... } > int f2() const { ... } > const(int) f3() { ... } > } > > Is there a difference

Meaning of const

2012-01-24 Thread H. S. Teoh
Hi all, I'm a bit confused by what 'const' means when used as part of a member function's signature: class A { int x; const int f1() { ... } int f2() const { ... } const(int) f3() { ... } } Is there a difference bet

Re: char* to long

2012-01-24 Thread mta`chrono
Why not just go the "good old" way? you char* should be zero terminated when coming from c. private import core.stdc.stdlib, std.stdio; void main() { const(char)* str = "1234567890".ptr; long lng = atoll(str); writeln(lng); }

Re: char* to long

2012-01-24 Thread Jonathan M Davis
On Tuesday, January 24, 2012 23:02:18 Mantis wrote: > 24.01.2012 22:48, Mars пишет: > > Hello everybody. > > I have to convert a char* (from a C function) to long. At the moment > > I'm using > > > >> long foo = to!long( to!string(bar) ); > > > > but this doesn't feel right... with 2 to calls. Is

Re: floating-WTF - Compiler-BUG with 64bit

2012-01-24 Thread %u
Shouldn't this go into 'digitalmars.D' ?

Re: char* to long

2012-01-24 Thread Mantis
24.01.2012 22:48, Mars пишет: Hello everybody. I have to convert a char* (from a C function) to long. At the moment I'm using long foo = to!long( to!string(bar) ); but this doesn't feel right... with 2 to calls. Is this the way to go? Or is there something better? Mars This seems to work:

char* to long

2012-01-24 Thread Mars
Hello everybody. I have to convert a char* (from a C function) to long. At the moment I'm using long foo = to!long( to!string(bar) ); but this doesn't feel right... with 2 to calls. Is this the way to go? Or is there something better? Mars

Re: KeyType, ValueType traits for hashes

2012-01-24 Thread Mantis
24.01.2012 20:49, bearophile пишет: Mantis: Of course, most likely that user already did type check, but if not, this will give less cryptic error: Error: static assert "Not associative array: int" instantiated from here: KeyType!(int) , instead of: Error: template instance KeyType!(int) Key

Re: actors library?

2012-01-24 Thread Timon Gehr
On 01/24/2012 07:51 PM, xancorreu wrote: Al 24/01/12 13:37, En/na Dejan Lekic ha escrit: Xan, read this article please: http://www.informit.com/articles/article.aspx?p=1609144 You have exactly what you are looking for in the D runtime and standard library. I read it and **after** I post the qu

Re: actors library?

2012-01-24 Thread xancorreu
Al 24/01/12 13:37, En/na Dejan Lekic ha escrit: Xan, read this article please: http://www.informit.com/articles/article.aspx?p=1609144 You have exactly what you are looking for in the D runtime and standard library. I read it and **after** I post the question. I don't know how std.concurrency

Re: KeyType, ValueType traits for hashes

2012-01-24 Thread bearophile
Mantis: > Of course, most likely that user already did type check, but if not, > this will give less cryptic error: > > Error: static assert "Not associative array: int" > instantiated from here: KeyType!(int) > > , instead of: > > Error: template instance KeyType!(int) KeyType!(int) does not

Re: floating-WTF - Compiler-BUG with 64bit

2012-01-24 Thread dennis luehring
Am 24.01.2012 19:13, schrieb Caligo: How did you compile it? As in my original post, it matters how you compile it. In this case (I'm on a 64-bit GNU/Linux system), compiling with '-inline' doesn't trigger the bug. im on win7 (64bit) - but the windows dmd2.057 isn't able to produce x64 code

Re: floating-WTF - Compiler-BUG with 64bit

2012-01-24 Thread Caligo
How did you compile it? As in my original post, it matters how you compile it. In this case (I'm on a 64-bit GNU/Linux system), compiling with '-inline' doesn't trigger the bug.

Re: floating-WTF - Compiler-BUG with 64bit

2012-01-24 Thread dennis luehring
Am 24.01.2012 18:49, schrieb sclytrack: dmd 2.057 give this result under windows/32bit calculate1: 1.5 1.5 calculate2: 1.5 1.5 calculate3: 1.5 1.5 so its seems to be an x64 compiler bug Yes, I missed my lessons in clear communication. - +

Re: floating-WTF

2012-01-24 Thread Caligo
On Tue, Jan 24, 2012 at 6:51 AM, Dejan Lekic wrote: > No, it is not a bug. > > Here is a hint: > > import std.stdio; > > int main() { >  float f; >  writeln(f); >  return 0; > } > > /+--- output --+ > nan > +--- end of output ---+/ > wow, what a great hint. sorry, but I'm not convinced

Re: floating-WTF

2012-01-24 Thread sclytrack
Yes, I missed my lessons in clear communication. - + The complete source files. - import std.stdio; void calculate1(float a, float b) { float s1 = 1.0f - a; float s2 = a * b;

Re: KeyType, ValueType traits for hashes

2012-01-24 Thread Mantis
24.01.2012 8:43, Andrej Mitrovic пишет: But I did implement them poorly, this is better: import std.traits; template KeyType(AA) if (isAssociativeArray!AA) { static if (is(AA V : V[K], K)) { alias K KeyType; } } template ValueType(AA) if (isAssociativeArray!AA

Re: Proper way to work with huge binary files

2012-01-24 Thread Jonathan M Davis
On Tuesday, January 24, 2012 15:53:48 C wrote: > Hello all. > After a quick recce on the main D site I couldn't find a how-to for large > binary files. > > Suppose I'm using an old machine with limited memory, and I want to compute > the MD5 hash of a 4 GB file. > Do I need to buffer the input as

Re: Proper way to work with huge binary files

2012-01-24 Thread Justin Whear
On Tue, 24 Jan 2012 15:53:48 +, C wrote: > Hello all. > After a quick recce on the main D site I couldn't find a how-to for > large binary files. > > Suppose I'm using an old machine with limited memory, and I want to > compute the MD5 hash of a 4 GB file. > Do I need to buffer the input as i

Re: floating-WTF

2012-01-24 Thread dennis luehring
double works correct under dmd64, but float not? what is the behavior of dmd32 in this szenario?

Re: floating-WTF

2012-01-24 Thread dennis luehring
can you give us a complete out-of-the-box compileable example (with imports,main,etc.) with both examples the working/and nonworking does it work correct with dmd(32bit)? is this "calculate2" needed to reproduce the behavior? and what compiler did you test: dmd64, (dmd32?), ...? Am 24.01.2012

Re: learn D & TDPL

2012-01-24 Thread Jonathan M Davis
On Tuesday, January 24, 2012 14:03:01 Gour wrote: > On Tue, 24 Jan 2012 13:41:31 +0100 > > "Dejan Lekic" wrote: > > Many things changed since the book has been released. I is > > strange that you did not see the link to the TDLP errata > > (http://erdani.com/tdpl/errata/) by now. :) > > I saw er

Proper way to work with huge binary files

2012-01-24 Thread C
Hello all. After a quick recce on the main D site I couldn't find a how-to for large binary files. Suppose I'm using an old machine with limited memory, and I want to compute the MD5 hash of a 4 GB file. Do I need to buffer the input as in C++? And how should I check for exceptions? Example code m

Re: floating-WTF

2012-01-24 Thread sclytrack
On 01/24/2012 04:41 PM, sclytrack wrote: On 01/24/2012 01:51 PM, Dejan Lekic wrote: No, it is not a bug. Here is a hint: import std.stdio; int main() { float f; writeln(f); return 0; } /+--- output --+ nan +--- end of output ---+/ I don't understand. I see now I forgot the input

Re: floating-WTF

2012-01-24 Thread sclytrack
On 01/24/2012 01:51 PM, Dejan Lekic wrote: No, it is not a bug. Here is a hint: import std.stdio; int main() { float f; writeln(f); return 0; } /+--- output --+ nan +--- end of output ---+/ I don't understand.

Re: floating-WTF

2012-01-24 Thread sclytrack
void calculate2(float a, float b) { float s1 = 1.0 - a; float s2 = a * b; writeln(s2); writeln(a * b); } Output: t*b= 0 t*b= 1.5 assume CS:.text._D4main10calculate2FffZv _D4main10calculate2FffZv: push

Re: Calling a C++ Object from D

2012-01-24 Thread Richard Webb
How about something like this (using Juno): /// import juno.com.core, std.stdio; abstract final class SystemInformation { mixin(uuid("C01B9BA0-BEA7-41BA-B604-D0A36F469133")); mixin Interfaces!(ISystemInformation); } interface ISystemInformation : IDispatch { mixin(uuid(

Re: learn D & TDPL

2012-01-24 Thread Gour
On Tue, 24 Jan 2012 13:41:31 +0100 "Dejan Lekic" wrote: > Many things changed since the book has been released. I is > strange that you did not see the link to the TDLP errata > (http://erdani.com/tdpl/errata/) by now. :) I saw errata, but one does not expect to consult book's errata for the c

Re: Calling a C++ Object from D

2012-01-24 Thread Richard Webb
I've never used the Windows update API, but isn't it a COM interface rather than a C++ interface? You can call those directly from D.

Re: KeyType, ValueType traits for hashes

2012-01-24 Thread Dejan Lekic
Andrej, I agree, they should be in std.traits .

Re: floating-WTF

2012-01-24 Thread Dejan Lekic
No, it is not a bug. Here is a hint: import std.stdio; int main() { float f; writeln(f); return 0; } /+--- output --+ nan +--- end of output ---+/

Re: Calling a C++ Object from D

2012-01-24 Thread Zachary Lund
On Tuesday, 24 January 2012 at 12:30:26 UTC, David Eagen wrote: I'm trying to understand how to call a C++ library from D. Specifically, the Windows Update API. My goal is rather simple in that I want to detect whether there is a reboot pending for the system. To do that I need to call the IS

Re: Calling a C++ Object from D

2012-01-24 Thread Dejan Lekic
Unfortunately, you cant use C++ namespaces. More about interfacing to C++ here: http://www.dlang.org/cpp_interface.html . The easiest way to solve this is to write a C function that will glue your code with the C++ library.

Re: learn D & TDPL

2012-01-24 Thread Dejan Lekic
Many things changed since the book has been released. I is strange that you did not see the link to the TDLP errata (http://erdani.com/tdpl/errata/) by now. :)

Re: actors library?

2012-01-24 Thread Dejan Lekic
Xan, read this article please: http://www.informit.com/articles/article.aspx?p=1609144 You have exactly what you are looking for in the D runtime and standard library.

Calling a C++ Object from D

2012-01-24 Thread David Eagen
I'm trying to understand how to call a C++ library from D. Specifically, the Windows Update API. My goal is rather simple in that I want to detect whether there is a reboot pending for the system. To do that I need to call the ISystemInformation::RebootRequired property but I don't know how to do

Re: dstep/internal/Reflection.d:205:0 expression "objcObject_"c == cast(char[])field is not constant or does not evaluate to a bool

2012-01-24 Thread Jacob Carlborg
On 2012-01-24 09:43, Robert Lumley wrote: hi all :) i'm new to D and i'm trying to get step to compile on the Mac. below is the template that gives the error: dstep/internal/Reflection.d:205:0 expression "objcObject_"c == cast(char[])field is not constant or does not evaluate to a bool private

Re: dstep/internal/Reflection.d:205:0 expression "objcObject_"c == cast(char[])field is not constant or does not evaluate to a bool

2012-01-24 Thread Jacob Carlborg
On 2012-01-24 13:26, Jacob Carlborg wrote: On 2012-01-24 09:43, Robert Lumley wrote: hi all :) i'm new to D and i'm trying to get step to compile on the Mac. below is the template that gives the error: dstep/internal/Reflection.d:205:0 expression "objcObject_"c == cast(char[])field is not const

Re: floating-WTF

2012-01-24 Thread sclytrack
--- alias float Real; Real lerp(Real t, Real a, Real b) { Real s2 = t * b; writeln("t*b= ", s2); writeln("t*b= ", t * b); return s2; } Output: t*b= 1.5 t*b= 1.5 - alias float Real; Real lerp(Real t,

Re: floating-WTF

2012-01-24 Thread sclytrack
t=0.75, a=-2.00, b=2.00, s1=-0.50, s2=0.00, rt1=-0.50, rt2=1.50 ::: 1.5 t = 0.75ok a = -2.0ok b = 2.0 ok s1 = -0.5 ok s2 = 1.5 //

Re: actors library?

2012-01-24 Thread Xan xan
Something like Class MyActor : Actor { receive { case i int: writeln("Received integer: ", i) } } pseudocode 2012/1/23 Timon Gehr : > On 01/23/2012 08:01 PM, Xan xan wrote: >> >> Hi. >> >> Is there any actors library in D. Spawn and etc is ok, but I want more >> high-level thing and acto

Re: floating-WTF

2012-01-24 Thread sclytrack
On 01/24/2012 04:13 AM, Caligo wrote: alias double Real; //alias float Real; // simple linear interpolation; I partitioned the internals to help me figure out what was happening. Real lerp(Real t, Real a, Real b){ Real s1 = (1.0 - t) * a; Real s2 = t * b; Real rt1 = s1 + s2; Real rt2

Re: learn D & TDPL

2012-01-24 Thread F i L
I own TDPL. The discrepancies are few and far between.

dstep/internal/Reflection.d:205:0 expression "objcObject_"c == cast(char[])field is not constant or does not evaluate to a bool

2012-01-24 Thread Robert Lumley
hi all :) i'm new to D and i'm trying to get step to compile on the Mac. below is the template that gives the error: dstep/internal/Reflection.d:205:0 expression "objcObject_"c == cast(char[])field is not constant or does not evaluate to a bool private template hasFieldImpl (T, string field