Scoped import bug?

2013-05-08 Thread Mike Linford
I'm not sure whether or not I've encountered a bug or whether my understanding of scoped imports is just faulty. blah.d: 1 module blah; 2 3 version(A) 4 { 5import std.range; 6 } 7 8 struct Blah(R) 9 { 10version(B) 11{ 12 import std.range; 13} 14s

Recommended way to compare / work with substrings?

2013-05-08 Thread Samuel Lampa
What is the recommended way to compare substrings (even of one character long)? I was wondering whetherI'm missing something when doing [1]: !(cast(string)myString[0..1] == ">" ? BR // Samuel [1] Longer context: string sequence = ""; File file = File("some_file_with_dna_sequences.txt","r")

Re: Recommended way to compare / work with substrings?

2013-05-08 Thread Samuel Lampa
On 05/09/2013 05:59 AM, Samuel Lampa wrote: What is the recommended way to compare substrings (even of one character long)? Ah, had already got the answer :) (but too long since I played with D last time ... :") ): http://stackoverflow.com/questions/14113470/check-if-string-starts-with-a-sub

Re: Variant associative arrays

2013-05-08 Thread evilrat
On Thursday, 9 May 2013 at 00:10:48 UTC, Byron Heads wrote: I have a variant associative array. In the example below I am wondering if there is a way to create the array without having to indicate the variant type on all of the values. Would like to be able to write code like #2, or something

Re: Argument S to typeof is not an expression

2013-05-08 Thread Meta
I tried defining opAdd for S as following: auto opAdd(alias rhs)() if (is(typeof(rhs) == S)) { return Test!(n + rhs.n); } Which I know is kind of silly, since I can't use opAdd to do a + b anymore, but it fails to compile anyway. The compiler says that b (of type Test) does not match a's v

Re: Physics libraries in D

2013-05-08 Thread Jeremy DeHaan
On Wednesday, 8 May 2013 at 13:01:52 UTC, evilrat wrote: On Wednesday, 8 May 2013 at 09:43:43 UTC, Mike Parker wrote: On Wednesday, 8 May 2013 at 09:37:51 UTC, KillerSponge wrote: Hi all, I've been searching around for physics libraries to use in a real-time 3D application (a game, to be more

Re: Variant associative arrays

2013-05-08 Thread bearophile
Byron Heads: I have a variant associative array. In the example below I am wondering if there is a way to create the array without having to indicate the variant type on all of the values. Would like to be able to write code like #2, or something cleaner/better for #1. ... // #1 This

Re: File I/O - rawWrite issues

2013-05-08 Thread H. S. Teoh
On Thu, May 09, 2013 at 01:11:00AM +0200, Carl wrote: > Wow, I feel silly. > > In the process of making sample code I found the problem: I have > been reading the output with a text editor instead of a hex editor. > To think I spent hours on this problem... *face palm* [...] No need to be embarra

Variant associative arrays

2013-05-08 Thread Byron Heads
I have a variant associative array. In the example below I am wondering if there is a way to create the array without having to indicate the variant type on all of the values. Would like to be able to write code like #2, or something cleaner/better for #1. This is intended for a library. Othe

Re: File I/O - rawWrite issues

2013-05-08 Thread Idan Arye
On Wednesday, 8 May 2013 at 21:34:00 UTC, Carl wrote: I am learning D so I thought this would be the correct place for this question (I assume I am making an error, not the compiler). I am writing arrays of ubytes using rawWrite to a file. Whenever I write arrays full of numbers I have no pro

Re: File I/O - rawWrite issues

2013-05-08 Thread Carl
Wow, I feel silly. In the process of making sample code I found the problem: I have been reading the output with a text editor instead of a hex editor. To think I spent hours on this problem... *face palm* Thanks for your quick replies.

Re: File I/O - rawWrite issues

2013-05-08 Thread Ali Çehreli
On 05/08/2013 02:46 PM, Meta wrote: >> For example: >> ubyte[] data = [5, 34, 9, 45]; >> file.rawWrite(data); // OKAY >> >> ubyte[] data = [0, 0, 0, 45]; >> file.rawWrite(data); // NOT OKAY > > Since ubytes are pretty much the same as chars, True from the point of view of sizes: they are both 8-

Re: File I/O - rawWrite issues

2013-05-08 Thread Meta
For example: ubyte[] data = [5, 34, 9, 45]; file.rawWrite(data); // OKAY ubyte[] data = [0, 0, 0, 45]; file.rawWrite(data); // NOT OKAY Since ubytes are pretty much the same as chars, I think writing 0 to the file will actually write the null character, which probably isn't a good thing.

File I/O - rawWrite issues

2013-05-08 Thread Carl
I am learning D so I thought this would be the correct place for this question (I assume I am making an error, not the compiler). I am writing arrays of ubytes using rawWrite to a file. Whenever I write arrays full of numbers I have no problems, but once I write an array with zeroes I can then

Silent compile error

2013-05-08 Thread Paul D. Anderson
Changed compilers from dmd 2.060 to dmd 2.062, running on Windows 7. Got a couple of errors relating to imports that I fixed but now it crashes with no indication of what went wrong. A Windows message dialog pops up stating that dmd.exe has stopped working. The "details" are posted below. The

Re: Deallocate array?

2013-05-08 Thread Steven Schveighoffer
On Wed, 08 May 2013 08:28:50 -0400, Matic Kukovec wrote: Thanks for the explanation Steve. Can you please give me a correct example of: - creating a dynamic string array auto arr = new char[N]; N can be a runtime value. - looping over it and adding values Not sure what you mean here.

Re: Physics libraries in D

2013-05-08 Thread evilrat
On Wednesday, 8 May 2013 at 09:43:43 UTC, Mike Parker wrote: On Wednesday, 8 May 2013 at 09:37:51 UTC, KillerSponge wrote: Hi all, I've been searching around for physics libraries to use in a real-time 3D application (a game, to be more precise). I know that Bullet and ODE are the big open so

Re: Argument S to typeof is not an expression

2013-05-08 Thread Dicebot
On Tuesday, 7 May 2013 at 15:05:40 UTC, Meta wrote: This is a little test to see if I can wrap types in structs and do some checking at compile time. For example, statically verifying in opAdd that neither number being added is negative. I added in the pragma to see what T's type is because I h

Re: Deallocate array?

2013-05-08 Thread Matic Kukovec
On Wednesday, 8 May 2013 at 12:03:08 UTC, Steven Schveighoffer wrote: On Wed, 08 May 2013 06:20:45 -0400, Matic Kukovec wrote: Was playing around with the code and found that this WORKS: (note the "app_temp_array.reserve(5000);" at the top, without this line it doesn't work) [snip] T

Re: Deallocate array?

2013-05-08 Thread Steven Schveighoffer
On Wed, 08 May 2013 06:20:45 -0400, Matic Kukovec wrote: Was playing around with the code and found that this WORKS: (note the "app_temp_array.reserve(5000);" at the top, without this line it doesn't work) [snip] The memory usage shrinks from 400MB to 2MB, which is right! Why? Thi

Re: Deallocate array?

2013-05-08 Thread Matic Kukovec
Was playing around with the code and found that this WORKS: (note the "app_temp_array.reserve(5000);" at the top, without this line it doesn't work) import std.stdio, core.memory, std.cstream, std.array; void main() { string[] temp_array; Appender!(string[]) app_temp_array =

Re: How to reserve memory for a slice in a struct

2013-05-08 Thread John Colvin
On Tuesday, 7 May 2013 at 11:49:07 UTC, evilrat wrote: On Tuesday, 7 May 2013 at 10:58:42 UTC, John Colvin wrote: ... int a[]; please don't use C style declarations, D style is "type followed by id": int[] a; woops, just copied it from the original post.

Re: Physics libraries in D

2013-05-08 Thread Mike Parker
On Wednesday, 8 May 2013 at 09:37:51 UTC, KillerSponge wrote: Hi all, I've been searching around for physics libraries to use in a real-time 3D application (a game, to be more precise). I know that Bullet and ODE are the big open source ones for C/C++, and I get the general impression that Bu

Re: Deallocate array?

2013-05-08 Thread Matic Kukovec
On Wednesday, 8 May 2013 at 08:59:57 UTC, Minas Mina wrote: On Tuesday, 7 May 2013 at 23:09:29 UTC, Matic Kukovec wrote: Hi I'm running Windows Vista 64 with dmd 2.062. I have a simple program: import std.stdio, core.memory, std.cstream; void main() { string[] temp_array; for

Re: Deallocate array?

2013-05-08 Thread Minas Mina
On Tuesday, 7 May 2013 at 23:09:29 UTC, Matic Kukovec wrote: Hi I'm running Windows Vista 64 with dmd 2.062. I have a simple program: import std.stdio, core.memory, std.cstream; void main() { string[] temp_array; for(int i=0;i<500;i++) { ++temp_arra

Re: Deallocate array?

2013-05-08 Thread Matic Kukovec
Thanks you guys for all the suggestions. bearophile: I am not creating 64 bit binaries. Tried compiling with or without the "-m32" flag. I have played around with GC.free, see below for more details. Juan Manuel Cabo: I tried your methods, but no change. The original program I described earlie