Re: How do I choose the correct primative?

2014-01-02 Thread Casper Færgemand
On Wednesday, 1 January 2014 at 04:17:30 UTC, Jake Thomas wrote: snip Are you looking for something like int_fast32_t and the likes from Boost? If you don't care terribly much for when your numbers overflow, then as others suggested, size_t and pttwhatever work fine.

Re: Is continuously seeding a random number generator performance intensive?

2014-01-02 Thread Chris Cain
On Thursday, 2 January 2014 at 22:01:01 UTC, monarch_dodra wrote: *This* comment is confusing me. What do you mean by "re-seed"? You mean a random seed? Once seeded, you shouldn't have to re-seed a PRNG: It'll generate random numbers forever. Or do you mean "re-seed" in the sense "reset"? Becau

Re: Pure Contract bug?

2014-01-02 Thread H. S. Teoh
On Thu, Jan 02, 2014 at 04:31:24PM -0800, David Held wrote: [...] > I think this is a language defect: > > struct Foo > { > int computed() pure { return x * y; } > int wrapper() const { return computed() + 5; } > > int x; > int y; > } > > void main() > { > } > > src\Bug2.d(4): E

Re: Is continuously seeding a random number generator performance intensive?

2014-01-02 Thread Frustrated
On Thursday, 2 January 2014 at 20:38:10 UTC, Jeroen Bollen wrote: D provides a set of Random Number Generators in std.random. I am writing an application which would create a 2D map of noise. To do this though, I'll have to calculate the same random numbers over and over again. (I cannot store

Re: Pure Contract bug?

2014-01-02 Thread David Held
On 2/4/2012 12:45 PM, Timon Gehr wrote: [...] Pure does not imply const in D. [...] I think this is a language defect: struct Foo { int computed() pure { return x * y; } int wrapper() const { return computed() + 5; } int x; int y; } void main() { } src\Bug2.d(4): Error: muta

Re: Pure Contract bug?

2014-01-02 Thread David Held
On 2/4/2012 2:04 PM, Era Scarecrow wrote: [...] struct X { int i; pure int squaredPlus(int x) { return x*x + i } alias squaredPlus sqp; } X st(15); writeln(st.sqp(0)); //15 int i1 = st.sqp(10); st.i++; int i2 = st.sqp(10); st.i++; int i3 = st.sqp(10)

Re: Is continuously seeding a random number generator performance intensive?

2014-01-02 Thread monarch_dodra
On Thursday, 2 January 2014 at 20:38:10 UTC, Jeroen Bollen wrote: D provides a set of Random Number Generators in std.random. I am writing an application which would create a 2D map of noise. To do this though, I'll have to calculate the same random numbers over and over again. (I cannot store

Is continuously seeding a random number generator performance intensive?

2014-01-02 Thread Jeroen Bollen
D provides a set of Random Number Generators in std.random. I am writing an application which would create a 2D map of noise. To do this though, I'll have to calculate the same random numbers over and over again. (I cannot store them, that'd take a horrible amount of RAM. ) Is it good to re-s

Re: How to handle char* to string from C functions?

2014-01-02 Thread bearophile
Gary Willoughby: I've noticed that const(char)** can be accessed via indexes: writefln("%s", pp[0].to!(string)); //etc. cool! This is a feature that works with all pointers to a sequence of items, like in C. But array bounds are not verified, so it's more bug-prone. So if you know the leng

Re: Struct field reordering

2014-01-02 Thread monarch_dodra
On Thursday, 2 January 2014 at 16:42:04 UTC, Justin Whear wrote: http://dlang.org/phobos/std_typecons.html#.alignForSize Wow, that interface is horrible! It becomes a real mess if you have more than 3 members... They should have used something like http://dlang.org/phobos/std_bitmanip.html#.

Re: Struct field reordering

2014-01-02 Thread bearophile
Justin Whear: http://dlang.org/phobos/std_typecons.html#.alignForSize Thank you, I have never seen that, nice :-) We should advertize more such D things on Reddit :-) http://www.reddit.com/r/programming/comments/1u660a/the_lost_art_of_c_structure_packing/ Bye, bearophile

Re: Struct field reordering

2014-01-02 Thread Justin Whear
On Thu, 02 Jan 2014 02:11:11 +, bearophile wrote: > Seen this on Reddit: > > http://www.catb.org/esr/structure-packing/ > > It could be useful to have in Phobos some template that given pair-name > pairs (or a struct type) returns those fields in a better packed order > (without using align(

Re: Struct field reordering

2014-01-02 Thread monarch_dodra
On Thursday, 2 January 2014 at 02:11:13 UTC, bearophile wrote: Seen this on Reddit: http://www.catb.org/esr/structure-packing/ It could be useful to have in Phobos some template that given pair-name pairs (or a struct type) returns those fields in a better packed order (without using align())

Re: How to handle char* to string from C functions?

2014-01-02 Thread uc
i'll answer in code http://dpaste.dzfl.pl/2bb1a1a8

Re: How to handle char* to string from C functions?

2014-01-02 Thread Gary Willoughby
On Thursday, 2 January 2014 at 15:31:25 UTC, bearophile wrote: Gary Willoughby: Another question: how do i convert const(char)** to string[]? If you know that you have N strings, then a solution is (untested): pp[0 .. N].map!text.array If it doesn't work, try: pp[0 .. N].map!(to!string).

Re: How to handle char* to string from C functions?

2014-01-02 Thread monarch_dodra
On Thursday, 2 January 2014 at 15:53:40 UTC, Adam D. Ruppe wrote: On Thursday, 2 January 2014 at 15:31:25 UTC, bearophile wrote: If you know that you have N strings, then a solution is (untested): Or if it is zero terminated, maybe pp.until!"a is null".map!text.array Though personally I'd j

Re: Task to throw away string parts, use joiner and splitter not very successful

2014-01-02 Thread monarch_dodra
On Thursday, 2 January 2014 at 15:50:10 UTC, monarch_dodra wrote: On Wednesday, 1 January 2014 at 07:40:40 UTC, Dfr wrote: And one more problem here: string name = "test"; auto nameparts = splitter(name, '.'); writeln(typeof(joiner(nameparts, ".").array).stringof); This prints "dchar[

Re: How to handle char* to string from C functions?

2014-01-02 Thread Adam D. Ruppe
On Thursday, 2 January 2014 at 15:31:25 UTC, bearophile wrote: If you know that you have N strings, then a solution is (untested): Or if it is zero terminated, maybe pp.until!"a is null".map!text.array Though personally I'd just use the plain old for loop.

Re: Task to throw away string parts, use joiner and splitter not very successful

2014-01-02 Thread monarch_dodra
On Wednesday, 1 January 2014 at 07:40:40 UTC, Dfr wrote: And one more problem here: string name = "test"; auto nameparts = splitter(name, '.'); writeln(typeof(joiner(nameparts, ".").array).stringof); This prints "dchar[]", but i need char[] or string, how to get my 'string' back ?

Re: Task to throw away string parts, use joiner and splitter not very successful

2014-01-02 Thread monarch_dodra
On Tuesday, 31 December 2013 at 21:23:08 UTC, Rémy Mouëza wrote: I'd also suggest the following alternative, if you're going to discard a lot of last elements in your code: /// Return seq without its last element. auto poppedBack (T) (T seq) if (isInputRange!T) { seq.popBack; //

Re: How to handle char* to string from C functions?

2014-01-02 Thread uc
You are going to need the length of your c char*[] then a for-loop should do it :D

Re: Task to throw away string parts, use joiner and splitter not very successful

2014-01-02 Thread monarch_dodra
On Wednesday, 1 January 2014 at 00:19:39 UTC, bearophile wrote: Chris Cain: From your error message: isForwardRange!Separator Your separator is a character, which isn't a forward range. Try this: `auto name1 = joiner(nameparts[0 .. $-1], ".");` But splitting on a char is a common operation

Re: How to handle char* to string from C functions?

2014-01-02 Thread bearophile
Gary Willoughby: Another question: how do i convert const(char)** to string[]? If you know that you have N strings, then a solution is (untested): pp[0 .. N].map!text.array If it doesn't work, try: pp[0 .. N].map!(to!string).array Bye, bearophile

Re: How to handle char* to string from C functions?

2014-01-02 Thread Gary Willoughby
On Wednesday, 1 January 2014 at 23:09:05 UTC, Adam D. Ruppe wrote: On Wednesday, 1 January 2014 at 23:03:06 UTC, Gary Willoughby wrote: I'm calling an external C function which returns a string delivered via a char*. When i print this string out, like this: char* result = func();' you can th

Re: Converting char to int

2014-01-02 Thread monarch_dodra
On Wednesday, 1 January 2014 at 20:01:56 UTC, Caeadas wrote: Thanks much for the help, both of you :). I thought there might be a very simple way to do this, since it's so intuitive to change '4' to 4. There have been talks about it, but it hasn't been implemented yet. The idea was to provide

Re: Are modules analogous to namespaces in C# or packages in Java?

2014-01-02 Thread Dejan Lekic
On Wednesday, 1 January 2014 at 17:43:54 UTC, Afshin wrote: Modules confuse me as a way to organize code. If a module is composed of multiple classes, it seems that the module semantics in D encourages putting all those classes in one file. Can someone explain how to organize a set of classe

Re: Are modules analogous to namespaces in C# or packages in Java?

2014-01-02 Thread Mike Parker
On 1/2/2014 2:43 AM, Afshin wrote: Modules confuse me as a way to organize code. If a module is composed of multiple classes, it seems that the module semantics in D encourages putting all those classes in one file. Can someone explain how to organize a set of classes into a module (or namespac

Re: How to handle char* to string from C functions?

2014-01-02 Thread Gary Willoughby
On Wednesday, 1 January 2014 at 23:09:05 UTC, Adam D. Ruppe wrote: On Wednesday, 1 January 2014 at 23:03:06 UTC, Gary Willoughby wrote: I'm calling an external C function which returns a string delivered via a char*. When i print this string out, like this: char* result = func();' you can th

Re: Documenting contracts in Ddoc

2014-01-02 Thread Gary Willoughby
On Thursday, 2 January 2014 at 06:19:53 UTC, H. S. Teoh wrote: On Thu, Jan 02, 2014 at 03:42:53AM +, bearophile wrote: Ross Hays: >I am putting this topic in the learn forum because I may be >wrong >and it may be possible. If, however, it is not possible, that >maybe it is worth a officia