Re: Spurious imports in Phobos ?

2011-11-10 Thread Somedude
Le 09/11/2011 14:15, Trass3r a écrit : 2. what is your opinion about public import ? In C++, "hidden" or "implicit" #includes is a common source of compilation problems (order of #includes), I tend to think it's a bad thing. It can be quite useful. I use it often for C library wrappers. As soon

Database API

2011-11-10 Thread Somedude
Hello, what is the currently DB API considered usable today ? http://prowiki.org/wiki4d/wiki.cgi?DatabaseBindings#ODBC d-dbapi looked quite decent, but the source code is no longer available :( Thank you Dude

Re: Spurious imports in Phobos ?

2011-11-10 Thread Somedude
Le 09/11/2011 14:50, Jacob Carlborg a écrit : 2. what is your opinion about public import ? In C++, "hidden" or "implicit" #includes is a common source of compilation problems (order of #includes), I tend to think it's a bad thing. Sometimes public imports are useful. It's possible to emulate

Re: web development in D programming

2011-11-10 Thread Kapps
Speaking only for lighttpd, it didn't work too well for me when I tried it (using FCGI). First off, it does not seem to support multiplexing. As well as that, it had no way I could figure out for handling concurrent requests. So, the way every single request goes is: Lighttpd opens a connectio

Re: Is there a portable way to limit memory/cpu usage of a D application?

2011-11-10 Thread deadalnix
Le 09/11/2011 18:12, Dejan Lekic a écrit : I would be satisfied with something like POSIX.1-2001 setrlimit() . Sure nothing prevents me from using setrlimit() in my D app, but perhaps it is something to think about a portable way of doing that. One thing I like about my Java apps is that I can a

Re: Database API

2011-11-10 Thread Dejan Lekic
Somedude wrote: > Hello, > > what is the currently DB API considered usable today ? > > http://prowiki.org/wiki4d/wiki.cgi?DatabaseBindings#ODBC > > d-dbapi looked quite decent, but the source code is no longer available :( > > Thank you > > Dude Try this alternative - http://www.dsource.org

Why isn't the overflow flag set?

2011-11-10 Thread Simen Kjærås
I'm creating a Checked!T struct for integral values. The version attached works for the most part, but some parts confuse me, namely that the following operations do not set the overflow flag: uint.max + 1 ulong.max + 1 int.min - 1 uint.min - 1 long.min - 1 ulong.min - 1 uint.max << 1 long.ma

Re: Why isn't the overflow flag set?

2011-11-10 Thread Steven Schveighoffer
On Thu, 10 Nov 2011 12:24:30 -0500, Simen Kjærås wrote: I'm creating a Checked!T struct for integral values. The version attached works for the most part, but some parts confuse me, namely that the following operations do not set the overflow flag: uint.max + 1 ulong.max + 1 int.min - 1 uin

Re: Why isn't the overflow flag set?

2011-11-10 Thread Simen Kjærås
On Thu, 10 Nov 2011 18:56:37 +0100, Steven Schveighoffer wrote: On Thu, 10 Nov 2011 12:24:30 -0500, Simen Kjærås wrote: I'm creating a Checked!T struct for integral values. The version attached works for the most part, but some parts confuse me, namely that the following operations do

Re: Why isn't the overflow flag set?

2011-11-10 Thread Timon Gehr
On 11/10/2011 06:24 PM, Simen Kjærås wrote: I'm creating a Checked!T struct for integral values. The version attached works for the most part, but some parts confuse me, namely that the following operations do not set the overflow flag: uint.max + 1 ulong.max + 1 int.min - 1 uint.min - 1 long.m

Re: assert(obj) is a mystery

2011-11-10 Thread Davidson Corry
On 11/9/2011 5:12 PM, Jonathan M Davis wrote: As far as I can tell, "assert(obj)" MEANS "test the invariant without using the object". And I don't see the point of that. It's occasionally useful when debugging code - particularly when called from inside of the object rather than externally. A

Strange behaviour of var

2011-11-10 Thread Fabian
Hey guys, I've got a problem - I've just written a few lines to approximate PI with the Monte Carlo Method. This is my code: import std.stdio, std.conv, std.string, std.random; void main() { string buf; int n, hits; float x, y, pi; Random rnd; rnd.seed(u

Re: Strange behaviour of var

2011-11-10 Thread Tobias Brandt
'hits' and 'n' are both integers and hits < n, therefore hits/n = 0 in integer arithmetic. You need to convert at least one of them to a floating point type, e.g., with 'cast(double)(hits)/n'. On 10 November 2011 21:08, Fabian wrote: > Hey guys, > > I've got a problem - I've just written a few li

Re: Strange behaviour of var

2011-11-10 Thread Fabian
Thank you - now it works :)

pass array of objects to spawn

2011-11-10 Thread Ruslan Mullakhmetov
Hi folks, I need to create thread and pass to it array of objects wich will no longer use in main thread. The problem is that spawn only accepts immutables and i have no idea how to tell him that i transfer full ownership of the data to child thread. the code: import std.concurrency

Re: pass array of objects to spawn

2011-11-10 Thread Ali Çehreli
On 11/10/2011 01:06 PM, Ruslan Mullakhmetov wrote: Hi folks, I need to create thread and pass to it array of objects wich will no longer use in main thread. The problem is that spawn only accepts immutables and i have no idea how to tell him that i transfer full ownership of the data to child t

Re: pass array of objects to spawn

2011-11-10 Thread Timon Gehr
On 11/10/2011 10:06 PM, Ruslan Mullakhmetov wrote: Hi folks, I need to create thread and pass to it array of objects wich will no longer use in main thread. The problem is that spawn only accepts immutables and i have no idea how to tell him that i transfer full ownership of the data to child t

Re: Strange behaviour of var

2011-11-10 Thread Ali Çehreli
This is not related to your question. I just wanted to point out that it is better to use the normal increment operator in the majority of cases. (I avoid calling it pre-increment, because that name suggests a more complicated semantics than there actually is.) On 11/10/2011 12:08 PM, Fabian w

Re: Strange behaviour of var

2011-11-10 Thread Fabian
oh ... I see. Thank you ;)

Smartest way to read a number?

2011-11-10 Thread Fabian
Hey guys. I just want to write a few console applications. Usualy I have to read numbers to calculate some values. But what's the smartest way to read and convert the input? I've coded these lines: import std.stdio, std.string, std.conv; T readNumber(T)() { string buffer; stdin.

Re: Smartest way to read a number?

2011-11-10 Thread Tobias Brandt
import std.stdio; T readNumber(T)() { T result; stdin.readf("%s", &result); return result; } Throws a ConvException if the input string wasn't in the right format. On 10 November 2011 22:48, Fabian wrote: > Hey guys. > > I just want to write a few console applications. Usualy I have

Re: pass array of objects to spawn

2011-11-10 Thread Ruslan Mullakhmetov
On 2011-11-11 01:21:09 +0400, Ali Çehreli said: class Foo { } void worker( shared(Foo)[] data ) { //... } void main() { auto data = new shared(Foo)[10]; spawn( &worker, data ); } Thanks. I tried to use the second version, a lttle bit modified it for actual mutation and it i

Re: pass array of objects to spawn

2011-11-10 Thread Ruslan Mullakhmetov
On 2011-11-11 01:23:01 +0400, Timon Gehr said: class Foo { } void worker( shared(Foo[]) data_ ) { Foo[] data = cast() data_; // this cast is valid because data_ is never read from another thread after the cast //... } void main() { { auto data = new Foo[10];

Re: Smartest way to read a number?

2011-11-10 Thread Andrej Mitrovic
This: https://github.com/he-the-great/JPDLibs/tree/cmdln/cmdln The HTML docs explain how to use it. Not mine, but I think this would be a sweet addition to Phobos imo.

Re: Smartest way to read a number?

2011-11-10 Thread Fabian
Thanks a lot. That's exactly what I was searching for.

Re: Smartest way to read a number?

2011-11-10 Thread Fabian
Andrej Mitrovic wrote: > This: https://github.com/he-the-great/JPDLibs/tree/cmdln/cmdln > > The HTML docs explain how to use it. Not mine, but I think this would > be a sweet addition to Phobos imo. Thank you. :)

Re: Smartest way to read a number?

2011-11-10 Thread Jonathan M Davis
On Thursday, November 10, 2011 13:48 Fabian wrote: > Hey guys. > > I just want to write a few console applications. Usualy I have to read > numbers to calculate some values. But what's the smartest way to read and > convert the input? > > I've coded these lines: > > import std.stdio, std.string,

Re: pass array of objects to spawn

2011-11-10 Thread Ali Çehreli
On 11/10/2011 01:57 PM, Ruslan Mullakhmetov wrote: On 2011-11-11 01:21:09 +0400, Ali Çehreli said: class Foo { } void worker( shared(Foo)[] data ) { //... } void main() { auto data = new shared(Foo)[10]; spawn( &worker, data ); } Thanks. I tried to use the second version, a lttle bit modi

Re: IDE with renaming possibility

2011-11-10 Thread Lishaak Bystroushaak
I'm using linux too. I tried all IDEs for D, but all of them was pretty lame, so I'm using Kate/Geany. > I don't find an important feature: renaming variables/functions/etc. BTW: It's called refactoring.

Re: Smartest way to read a number?

2011-11-10 Thread Kai Meyer
I don't get the exception on Linux after a new line, I have to wait until EOF, which is typically the end of the program if reading from STDIN. Not very useful. import std.stdio; T readNumber(T)() { T result; stdin.readf("%s", &result); return result; } void main() { try {

Re: pass array of objects to spawn

2011-11-10 Thread Timon Gehr
On 11/10/2011 11:00 PM, Ruslan Mullakhmetov wrote: On 2011-11-11 01:23:01 +0400, Timon Gehr said: class Foo { } void worker( shared(Foo[]) data_ ) { Foo[] data = cast() data_; // this cast is valid because data_ is never read from another thread after the cast //... } void main() { { auto da

Re: Smartest way to read a number?

2011-11-10 Thread Tobias Brandt
Yes, you are right. You can make it work by changing to line buffering: stdin.setvbuf(null, _IOLBF); But at that point, another solution (like using std.conv.to) is probably the better choice. On 10 November 2011 23:40, Kai Meyer wrote: > I don't get the exception on Linux after a new line, I h

Re: pass array of objects to spawn

2011-11-10 Thread Timon Gehr
On 11/10/2011 11:23 PM, Ali Çehreli wrote: On 11/10/2011 01:57 PM, Ruslan Mullakhmetov wrote: On 2011-11-11 01:21:09 +0400, Ali Çehreli said: class Foo { } void worker( shared(Foo)[] data ) { //... } void main() { auto data = new shared(Foo)[10]; spawn( &worker, data ); } Thanks. I tried

Re: Strange behaviour of var

2011-11-10 Thread Timon Gehr
On 11/10/2011 10:45 PM, Fabian wrote: oh ... I see. Thank you ;) ++i is unidiomatic, and if the result is unused it means the same thing as i++. So, I'd actually go with i++. The only reason why one would use ++i is because it is less efficient for C++ iterators, but D does not have that pro

Re: Strange behaviour of var

2011-11-10 Thread Andrej Mitrovic
size_t can easily bite you* in the ass: import std.algorithm; void main() { int[] a; int val = max(0, a.length - 1); assert(val > 0); // NG, woops! } * = me That one is easy to catch, but in a complex expression you might have ints and size_t and everything gets converted to unsig

Re: pass array of objects to spawn

2011-11-10 Thread bearophile
Timon Gehr: > Interesting, apparently cast() does not remove shared. The semantics of cast() was never formalized, I think. People use this idiom, so I think we have to formalize what cast() exactly does. This is meat for Bugzilla or even for discussion topic in the main D newsgroup. Generally

Fields size property

2011-11-10 Thread Andrej Mitrovic
.sizeof on a struct works nicely since it's a POD, but this can't work on classes since it just returns the pointer size. I don't know whether this is useful all that much, but I'm curious how large my classes are. Anyway, since I couldn't find anything in Phobos I've got this working: import std

Re: Fields size property

2011-11-10 Thread Andrej Mitrovic
On 11/11/11, Andrej Mitrovic wrote: > foreach (type; RepresentationTypeTuple!Foo) { Way to screw that up. Fix: foreach (type; RepresentationTypeTuple!T) {

Re: Fields size property

2011-11-10 Thread Ali Çehreli
On 11/10/2011 05:44 PM, Andrej Mitrovic wrote: .sizeof on a struct works nicely since it's a POD, but this can't work on classes since it just returns the pointer size. I don't know whether this is useful all that much, but I'm curious how large my classes are. Anyway, since I couldn't find anyt

Re: Fields size property

2011-11-10 Thread Andrej Mitrovic
On 11/11/11, Ali Çehreli wrote: > This is the standard way: > > __traits(classInstanceSize, Foo) > > Ali > Thanks! It's also more reliable it seems. :)

shared lib

2011-11-10 Thread Ellery Newcomer
trying to build a .so file (actually, trying to resuscitate pyd) with gdc. celerid is spitting out gdc -fPIC -nostartfiles -shared -fdebug {lots of object files plus some link directives} which is spitting out /usr/bin/ld: /usr/lib64/libgphobos2.a(object_.o): relocation R_X86_64_32S against `_D

Re: pass array of objects to spawn

2011-11-10 Thread Ruslan Mullakhmetov
On 2011-11-11 02:48:52 +0400, Timon Gehr said: On 11/10/2011 11:00 PM, Ruslan Mullakhmetov wrote: On 2011-11-11 01:23:01 +0400, Timon Gehr said: class Foo { } void worker( shared(Foo[]) data_ ) { Foo[] data = cast() data_; // this cast is valid because data_ is never read from another threa

Re: Smartest way to read a number?

2011-11-10 Thread Fabian
Ok - Good to know. Thank you ;)