Re: duplicate symbol linker errors, my fault or D's?

2012-03-06 Thread Jacob Carlborg
On 2012-03-07 01:47, Jonathan M Davis wrote: On Tuesday, March 06, 2012 11:31:40 Jacob Carlborg wrote: On 2012-03-06 08:56, Jonathan M Davis wrote: On Tuesday, March 06, 2012 08:29:53 Jacob Carlborg wrote: On 2012-03-06 02:21, Jonathan M Davis wrote: On Tuesday, March 06, 2012 01:53:02 Zach t

Re: D RTTI?

2012-03-06 Thread Jacob Carlborg
On 2012-03-07 00:19, H. S. Teoh wrote: On Tue, Mar 06, 2012 at 11:40:19PM +0100, Artur Skawina wrote: On 03/06/12 20:37, H. S. Teoh wrote: On Tue, Mar 06, 2012 at 01:51:51AM +0100, Artur Skawina wrote: [...] class A { string prop1; int prop2; void serialize(this THIS)() { _

Re: D RTTI?

2012-03-06 Thread Jacob Carlborg
On 2012-03-06 19:17, H. S. Teoh wrote: On Tue, Mar 06, 2012 at 08:17:07AM +0100, Jacob Carlborg wrote: On 2012-03-05 21:16, H. S. Teoh wrote: I know D doesn't really have RTTI yet, but I'm experimenting with "faking" it by doing something like: class A { string prop1;

Re: 0 < negative loop condition bug or misunderstanding on my part

2012-03-06 Thread H. S. Teoh
> On 03/06/2012 10:05 PM, ixid wrote: > > Ah, thank you, so it's wrapping. That seems like a bad idea, what is > > the benefit to size being unsigned rather than signed? Because it doesn't make sense to have something with a negative size? > > This case would seem like one where allowing negativ

Re: 0 < negative loop condition bug or misunderstanding on my part

2012-03-06 Thread Ali Çehreli
On 03/06/2012 10:05 PM, ixid wrote: > Ah, thank you, so it's wrapping. That seems like a bad idea, what is the > benefit to size being unsigned rather than signed? This case would seem > like one where allowing negatives is clearly better and more intuitive. There are probably hundreds of discuss

Re: 0 < negative loop condition bug or misunderstanding on my part

2012-03-06 Thread ixid
Ah, thank you, so it's wrapping. That seems like a bad idea, what is the benefit to size being unsigned rather than signed? This case would seem like one where allowing negatives is clearly better and more intuitive.

Re: 0 < negative loop condition bug or misunderstanding on my part

2012-03-06 Thread H. S. Teoh
On Wed, Mar 07, 2012 at 06:11:18AM +0100, ixid wrote: > I'm writing my first basic algorithms, this one is merge sort. This > version throws an exception when array.length - setSize is negative > (which should be fine, the rest of my function would deal with it): [...] array.length is of type size

Re: 0 < negative loop condition bug or misunderstanding on my part

2012-03-06 Thread Ali Çehreli
On 03/06/2012 09:11 PM, ixid wrote: > I'm writing my first basic algorithms, this one is merge sort. This > version throws an exception when array.length - setSize is negative > (which should be fine, the rest of my function would deal with it): > > template mergeSort(T) > { > void mergeSort(ref T

0 < negative loop condition bug or misunderstanding on my part

2012-03-06 Thread ixid
I'm writing my first basic algorithms, this one is merge sort. This version throws an exception when array.length - setSize is negative (which should be fine, the rest of my function would deal with it): template mergeSort(T) { void mergeSort(ref T[] array, const T setSize = 100)

Re: Why constructs can not be private?

2012-03-06 Thread Jonathan M Davis
On Tuesday, March 06, 2012 22:24:55 Caligo wrote: > module A; > > private struct A { } > private A a; > private mixin template magic() { } > private void foo() { } > > //- > > module B; > > import A; > > void main() { > A b; // #1 works Doesn't construct anything. It ju

Why constructs can not be private?

2012-03-06 Thread Caligo
module A; private struct A { } private A a; private mixin template magic() { } private void foo() { } //- module B; import A; void main() { A b; // #1 works b = a; // #2 ERROR foo(); // #3 ERROR } struct B{ mixin magic; // #4 works } What's the point of declar

Re: Is there a wrapper for libuv?

2012-03-06 Thread James Miller
On 7 March 2012 14:47, Tyler Jameson Little wrote: > >> You shouldn't have to do anything with them, just write bindings for >> the api, with all the correct types. >> >> -- >> James Miller > > > Thanks! I guess I got a little over-zealous in porting stuff over. I just > need to create extern (C)

Re: Is there a wrapper for libuv?

2012-03-06 Thread Tyler Jameson Little
You shouldn't have to do anything with them, just write bindings for the api, with all the correct types. -- James Miller Thanks! I guess I got a little over-zealous in porting stuff over. I just need to create extern (C) bindings for the functions that will be used, right?

Re: Is there a wrapper for libuv?

2012-03-06 Thread James Miller
On 7 March 2012 13:52, Tyler Jameson Little wrote: > I hope this is the right place to ask this. > > libuv is the evented IO library that nodejs uses internally. It is basically > glue for a bunch of other libraries (libev, c-ares, libeio and others). > > https://github.com/joyent/libuv > > Is the

Is there a wrapper for libuv?

2012-03-06 Thread Tyler Jameson Little
I hope this is the right place to ask this. libuv is the evented IO library that nodejs uses internally. It is basically glue for a bunch of other libraries (libev, c-ares, libeio and others). https://github.com/joyent/libuv Is there already working on a wrapper? I would very much like to u

Re: Why is std.algorithm.reduce impure?

2012-03-06 Thread bearophile
H. S. Teoh: > But why can't 'this' be const? For example, why does the compiler reject > this: > > class A { > int[] data; > pure const int sum() { > return reduce!"a*b"(data); > } > } > > I'm not modifying data at at al

Re: duplicate symbol linker errors, my fault or D's?

2012-03-06 Thread Jonathan M Davis
On Tuesday, March 06, 2012 11:31:40 Jacob Carlborg wrote: > On 2012-03-06 08:56, Jonathan M Davis wrote: > > On Tuesday, March 06, 2012 08:29:53 Jacob Carlborg wrote: > >> On 2012-03-06 02:21, Jonathan M Davis wrote: > >>> On Tuesday, March 06, 2012 01:53:02 Zach the Mystic wrote: > Reading th

Re: Why is std.algorithm.reduce impure?

2012-03-06 Thread Jonathan M Davis
On Tuesday, March 06, 2012 14:41:01 H. S. Teoh wrote: > Why is std.algorithm.reduce not marked pure? It makes it impossible to > do things like this: > > pure const int product(int[] args) { > return reduce!"a * b"(args); > } You'd have to look through the implementation and possibly tweak it to

Re: How to cast a int to a string?

2012-03-06 Thread Chris Pons
On Tuesday, 6 March 2012 at 23:19:03 UTC, H. S. Teoh wrote: On Wed, Mar 07, 2012 at 12:13:54AM +0100, Chris Pons wrote: I'm trying to update a string easily whenever I change a numeric component of the string. I've tried to do this so far with no result: [...] Try this: import std.co

Re: How to cast a int to a string?

2012-03-06 Thread H. S. Teoh
On Wed, Mar 07, 2012 at 12:13:54AM +0100, Chris Pons wrote: > I'm trying to update a string easily whenever I change a numeric > component of the string. I've tried to do this so far with no > result: [...] Try this: import std.conv; ... int i = 1234; string s = to

Re: htod - const

2012-03-06 Thread Andrej Mitrovic
On 3/6/12, Trass3r wrote: > Sadly, using regular expressions is much more efficient. Do you have some script that does that and sorta works? I've tried others (e.g. dstep but couldn't get LLVM to compile unfortunately..).

Re: D RTTI?

2012-03-06 Thread H. S. Teoh
On Tue, Mar 06, 2012 at 11:40:19PM +0100, Artur Skawina wrote: > On 03/06/12 20:37, H. S. Teoh wrote: > > On Tue, Mar 06, 2012 at 01:51:51AM +0100, Artur Skawina wrote: > > [...] > >> class A { > >>string prop1; > >>int prop2; > >> > >>void serialize(this THIS)() { > >> __serializ

How to cast a int to a string?

2012-03-06 Thread Chris Pons
I'm trying to update a string easily whenever I change a numeric component of the string. I've tried to do this so far with no result: while( testInt < 10 ) string testString = "Test "; int testInt = 0; testString ~= toString(testInt) testInt++; or this: testString ~= cast(string)(testInt) B

Re: Why is std.algorithm.reduce impure?

2012-03-06 Thread H. S. Teoh
On Tue, Mar 06, 2012 at 03:00:16PM -0800, H. S. Teoh wrote: [...] > But why can't 'this' be const? For example, why does the compiler > reject this: > > class A { > int[] data; > pure const int sum() { > return reduce!"a*b"(data); >

Re: Why is std.algorithm.reduce impure?

2012-03-06 Thread H. S. Teoh
On Tue, Mar 06, 2012 at 11:51:05PM +0100, Adam D. Ruppe wrote: > On Tuesday, 6 March 2012 at 22:48:30 UTC, H. S. Teoh wrote: > >Oh? what's wrong with the const? > > test10.d(3): Error: function test10.product without 'this' cannot be > const/immutable > > It works if you put parens on it: > >

Re: Why is std.algorithm.reduce impure?

2012-03-06 Thread Adam D. Ruppe
On Tuesday, 6 March 2012 at 22:48:30 UTC, H. S. Teoh wrote: Oh? what's wrong with the const? test10.d(3): Error: function test10.product without 'this' cannot be const/immutable It works if you put parens on it: pure const(int) product(int[] args) { Without the parenthesis, D want

Re: Why is std.algorithm.reduce impure?

2012-03-06 Thread H. S. Teoh
On Tue, Mar 06, 2012 at 11:42:00PM +0100, Adam D. Ruppe wrote: > On Tuesday, 6 March 2012 at 22:39:20 UTC, H. S. Teoh wrote: > >Why is std.algorithm.reduce not marked pure? > > It doesn't have to be - templates are inferred to be > pure or not. > > If you take the const off that signature, your e

Re: htod - const

2012-03-06 Thread Trass3r
Am 06.03.2012, 20:13 Uhr, schrieb maarten van damme : I wouldn't say that it sucks. It has really helped a lot in porting some simple header files. It goes terribly bad on the more complex though. Sadly, using regular expressions is much more efficient. At least those don't destroy the so

Re: Why is std.algorithm.reduce impure?

2012-03-06 Thread Adam D. Ruppe
On Tuesday, 6 March 2012 at 22:39:20 UTC, H. S. Teoh wrote: Why is std.algorithm.reduce not marked pure? It doesn't have to be - templates are inferred to be pure or not. If you take the const off that signature, your example works in today's dmd.

Re: D RTTI?

2012-03-06 Thread Artur Skawina
On 03/06/12 20:37, H. S. Teoh wrote: > On Tue, Mar 06, 2012 at 01:51:51AM +0100, Artur Skawina wrote: > [...] >> class A { >>string prop1; >>int prop2; >> >>void serialize(this THIS)() { >> __serialize(cast(THIS*)&this); >>} >> } >> >> void __serialize(T)(T* obj) { >>write

Why is std.algorithm.reduce impure?

2012-03-06 Thread H. S. Teoh
Why is std.algorithm.reduce not marked pure? It makes it impossible to do things like this: pure const int product(int[] args) { return reduce!"a * b"(args); } T -- Life is unfair. Ask too much from it, and it may decide you don't deserve what you have now eith

Re: Array of derived class objects?

2012-03-06 Thread Andrej Mitrovic
You can use a cast as a workaround: A[] objs = [cast(A)new B, new C ]; This bug has been around for a while, the first time I've seen it mentioned was in the second code snippet in this blog post: http://klickverbot.at/blog/2010/11/announcing-d-support-in-swig/

Re: htod - const

2012-03-06 Thread dnewbie
Thanks Trass3r. On Tue, Mar 6, 2012, at 05:50 PM, Trass3r wrote: > > Why is 'const' removed? > > cause htod sucks. > D1 didn't have const and htod wasn't updated for ages. >

Re: Array of derived class objects?

2012-03-06 Thread simendsjo
On Tue, 06 Mar 2012 20:27:56 +0100, H. S. Teoh wrote: Code: // test.d class A {} class B : A {} class C : A {} void main() { A[] objs = [ new B, new C ];// line 6 } Compiler error: test.d(6): Error: cannot implicitly conv

Re: Array of derived class objects?

2012-03-06 Thread Ali Çehreli
On 03/06/2012 11:27 AM, H. S. Teoh wrote: Code: // test.d class A {} class B : A {} class C : A {} void main() { A[] objs = [ new B, new C ];// line 6 } Compiler error: test.d(6): Error: cannot implicitly convert expre

Re: D RTTI?

2012-03-06 Thread Timon Gehr
On 03/06/2012 08:37 PM, H. S. Teoh wrote: On Tue, Mar 06, 2012 at 01:51:51AM +0100, Artur Skawina wrote: [...] class A { string prop1; int prop2; void serialize(this THIS)() { __serialize(cast(THIS*)&this); } } void __serialize(T)(T* obj) { writef("%s {\n", typeid(*o

Re: D RTTI?

2012-03-06 Thread H. S. Teoh
On Tue, Mar 06, 2012 at 01:51:51AM +0100, Artur Skawina wrote: [...] > class A { >string prop1; >int prop2; > >void serialize(this THIS)() { > __serialize(cast(THIS*)&this); >} > } > > void __serialize(T)(T* obj) { >writef("%s {\n", typeid(*obj)); >foreach (name; __t

Array of derived class objects?

2012-03-06 Thread H. S. Teoh
Code: // test.d class A {} class B : A {} class C : A {} void main() { A[] objs = [ new B, new C ];// line 6 } Compiler error: test.d(6): Error: cannot implicitly convert expression (new B) of type test.A to test.C

Re: htod - const

2012-03-06 Thread maarten van damme
trass3r, I wouldn't say that it sucks. It has really helped a lot in porting some simple header files. It goes terribly bad on the more complex though.

Re: How do I force something onto the heap? (need for libev)

2012-03-06 Thread deadalnix
Le 06/03/2012 05:34, Tyler Jameson Little a écrit : I've been playing with libev in D lately, and I've run into a problem. I've been able to hack around it, but it'd like to find a better, more general solution. Here's a link to the code: https://github.com/beatgammit/fun-with-d/blob/master/libe

Re: D RTTI?

2012-03-06 Thread H. S. Teoh
On Tue, Mar 06, 2012 at 08:17:07AM +0100, Jacob Carlborg wrote: > On 2012-03-05 21:16, H. S. Teoh wrote: > >I know D doesn't really have RTTI yet, but I'm experimenting with > >"faking" it by doing something like: > > > > class A { > > string prop1; > > int prop2; > >

Re: Shutting down thread with Socket blocking for connection

2012-03-06 Thread Vidar Wahlberg
On 2012-03-05 09:38, Dmitry Olshansky wrote: ... while(working){ if(select(set, null, null, 10) > 0){ //10 usec wait on a socket, may do plain 0 sock.accept(); // no blocking here } set.reset(); set.add(sock); receiveTimeout(dur!"us"(1), (int code){ working = false; }); } ... Thanks for the an

Re: htod - const

2012-03-06 Thread Trass3r
Why is 'const' removed? cause htod sucks. D1 didn't have const and htod wasn't updated for ages.

htod - const

2012-03-06 Thread dnewbie
I have this file tmp.h: const char *getvalue(const char *key); I run htod tmp.h and I've got the output --- /* Converted to D from tmp.h by htod */ module tmp; //C const char *getvalue(const char *key); extern (C): char * getvalue(char *key); -

Re: SysTime in a Struct

2012-03-06 Thread albatroz
Hi Ali, only today I had the time to implement your suggestion it's working now has expected. Thank you for your patience, also thank you for the work translating such a good D book to English. On Friday, 2 March 2012 at 00:00:10 UTC, Ali Çehreli wrote: On 03/01/2012 03:46 PM, albatroz wr

Re: Translate for chars to strings

2012-03-06 Thread Andrej Mitrovic
Hmm somehow I missed that. Thanks. On 3/6/12, Ali Çehreli wrote: > On 03/05/2012 04:32 PM, Andrej Mitrovic wrote: >> There's a really useful function 'translate' in std.string, used like >> this: >> >> __gshared dchar[dchar] MangleTable; >> >> shared static this() >> { >> MangleTable = >>

Re: D RTTI?

2012-03-06 Thread Timon Gehr
On 03/06/2012 01:51 AM, Artur Skawina wrote: ... Real programmers don't use mixins, :^) You got it reverse.

Re: duplicate symbol linker errors, my fault or D's?

2012-03-06 Thread Jacob Carlborg
On 2012-03-06 08:56, Jonathan M Davis wrote: On Tuesday, March 06, 2012 08:29:53 Jacob Carlborg wrote: On 2012-03-06 02:21, Jonathan M Davis wrote: On Tuesday, March 06, 2012 01:53:02 Zach the Mystic wrote: Reading the documentation about compiler options and flags here: http://dlang.org/dmd-o