Looking for something similar to Python's bisect_right

2013-10-30 Thread Zeke
Hello, I'm on day 2 of learning D. I've learned C, C++, Java, Python, Ruby in University, but I wanted to broaden my palette by picking up D. This project is a basic implementation of Project Euler problem 10. I build an array of primes, and for each new test number I check if the test is

Re: Looking for something similar to Python's bisect_right

2013-10-30 Thread Ali Çehreli
On 10/29/2013 11:04 PM, Zeke wrote: lowerBound and friends are related: http://dlang.org/phobos/std_range.html#.lowerBound Ali

Re: Dynamic associative array, to hold many values per key

2013-10-30 Thread bearophile
Logesh Pillay: using struct as a key to an associative array worked fine without opHash and other special methods. It works as long as you don't put reference types (like dynamic arrays and strings) as members of that struct. Bye, bearophile

Re: How do you implement a recursive walker of a tree with a lazy range?

2013-10-30 Thread bearophile
Chris Cain: InputRange!Tree walk() { return inputRangeObject(chain( [this], children.map!(a=a.walk())().joiner())); } I have used your nice idea to create another partial D solution for this task: http://rosettacode.org/wiki/Tree_traversal#D

Re: Looking for something similar to Python's bisect_right

2013-10-30 Thread qznc
On Wednesday, 30 October 2013 at 06:04:36 UTC, Zeke wrote: Hello, I'm on day 2 of learning D. I've learned C, C++, Java, Python, Ruby in University, but I wanted to broaden my palette by picking up D. This project is a basic implementation of Project Euler problem 10. I build an array of

Re: How do you implement a recursive walker of a tree with a lazy range?

2013-10-30 Thread Andrej Mitrovic
On 10/30/13, Chris Cain clc...@uncg.edu wrote: I'm not confident that this is the most efficient way, but it works. It allocates, I'm looking for a lazy range. I would be surprised that such a common task as iterating a tree is not possible without using classes and workarounds.

Re: directx bindings problem

2013-10-30 Thread Benjamin Thaut
Am 30.10.2013 04:18, schrieb evilrat: On Tuesday, 29 October 2013 at 19:40:40 UTC, Benjamin Thaut wrote: omg! i can't believe this :( i have tried this too first(http://www.dsource.org/projects/bindings/wiki/DirectX), and it was somewhat crappy, so i start my own tranlation, all was fine until

Re: How do you implement a recursive walker of a tree with a lazy range?

2013-10-30 Thread Benjamin Thaut
Am 30.10.2013 15:58, schrieb Andrej Mitrovic: On 10/30/13, Chris Cain clc...@uncg.edu wrote: I'm not confident that this is the most efficient way, but it works. It allocates, I'm looking for a lazy range. I would be surprised that such a common task as iterating a tree is not possible

Re: directx bindings problem

2013-10-30 Thread evilrat
On Wednesday, 30 October 2013 at 15:18:57 UTC, Benjamin Thaut wrote: Well we all make problems. Give me a note when you are done with complete directx bindings as I'm also interrested in having minimal up to date directx bindings. Also its always apperciated to thank you a person which

Re: How do you implement a recursive walker of a tree with a lazy range?

2013-10-30 Thread Chris Cain
On Wednesday, 30 October 2013 at 14:58:21 UTC, Andrej Mitrovic wrote: It allocates, I'm looking for a lazy range. I would be surprised that such a common task as iterating a tree is not possible without using classes and workarounds. It allocates, but it's still a lazy range. It only

Re: How do you implement a recursive walker of a tree with a lazy range?

2013-10-30 Thread Chris Cain
On Wednesday, 30 October 2013 at 12:55:41 UTC, bearophile wrote: I have used your nice idea to create another partial D solution for this task: http://rosettacode.org/wiki/Tree_traversal#D ... snip ... Very cool! It's pretty close to being done. I'd have to give some real thought to how a

Re: directx bindings problem

2013-10-30 Thread Benjamin Thaut
Am 30.10.2013 17:53, schrieb evilrat: On Wednesday, 30 October 2013 at 15:18:57 UTC, Benjamin Thaut wrote: Well we all make problems. Give me a note when you are done with complete directx bindings as I'm also interrested in having minimal up to date directx bindings. Also its always

Re: How do you implement a recursive walker of a tree with a lazy range?

2013-10-30 Thread Chris Cain
On Wednesday, 30 October 2013 at 16:50:33 UTC, Chris Cain wrote: you would avoid allocations. Actually, let me clarify. You'd avoid *those* allocations. inputRangeObject allocates a class. Unfortunately, I'm not certain it's possible to do this cleanly without such a thing using

Re: How do you implement a recursive walker of a tree with a lazy range?

2013-10-30 Thread Philippe Sigaud
On Wed, Oct 30, 2013 at 1:55 PM, bearophile bearophileh...@lycos.comwrote: alias VisitRange(T) = InputRange!(const Tree!T); Does that syntax come with DMD 2.064? The (T) part, I mean.

Re: How do you implement a recursive walker of a tree with a lazy range?

2013-10-30 Thread Dicebot
On Wednesday, 30 October 2013 at 17:31:10 UTC, Philippe Sigaud wrote: On Wed, Oct 30, 2013 at 1:55 PM, bearophile bearophileh...@lycos.comwrote: alias VisitRange(T) = InputRange!(const Tree!T); Does that syntax come with DMD 2.064? The (T) part, I mean. Yes.

Re: How do you implement a recursive walker of a tree with a lazy range?

2013-10-30 Thread Andrej Mitrovic
On 10/30/13, Philippe Sigaud philippe.sig...@gmail.com wrote: Does that syntax come with DMD 2.064? The (T) part, I mean. Yes. Glad to see you here btw, do you have your own solution to the problem?

Re: parse int error

2013-10-30 Thread Ali Çehreli
On 10/29/2013 06:02 PM, Peter Eisenhower wrote: I am confused as to why I cannot pass the return of the tag attribute directly into the parse int. // This works string s = xml.tag.attr[key]; int key = parse!int(s); // Compile error on these int key = parse!int(xml.tag.attr[key]); int key =

Re: How do you implement a recursive walker of a tree with a lazy range?

2013-10-30 Thread Philippe Sigaud
On Wed, Oct 30, 2013 at 7:09 PM, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: On 10/30/13, Philippe Sigaud philippe.sig...@gmail.com wrote: Does that syntax come with DMD 2.064? The (T) part, I mean. Yes. Ah, that's cool! I've been waiting for that one for years. Glad to see you

Re: Looking for something similar to Python's bisect_right

2013-10-30 Thread Zeke
On Wednesday, 30 October 2013 at 14:17:22 UTC, qznc wrote: Why do you want to find the exact prime first? Just check against sqrt(num) in the loop. auto upper = cast(ulong)sqrt(cast(double)num)) + 1; foreach(ulong prime; primes) { if (prime upper) return true; if (num % prime == 0) return

Re: Looking for something similar to Python's bisect_right

2013-10-30 Thread Zeke
On Wednesday, 30 October 2013 at 06:10:59 UTC, Ali Çehreli wrote: On 10/29/2013 11:04 PM, Zeke wrote: lowerBound and friends are related: http://dlang.org/phobos/std_range.html#.lowerBound Ali lowerBound returns a range with the last value being the sqrt, so I can't directly iterate over

Set variable at compile time

2013-10-30 Thread Craig Dillabaugh
Hello, I am writing code that uses a structure containing an array of points where the points may be of arbitrary dimension (though generally small). I would like to be able to pass the point dimension to my structure as a template parameter. One solution is to create instances of these

Re: Set variable at compile time

2013-10-30 Thread Adam D. Ruppe
It won't really work on the command line alone, but the way I do it is a two step thing. First, make the thing use a config module: import myproject.config; alias Thing Thing_Impl!dim; then you go ahead and use Thing, which is instantiated with the dimension. Then the user makes a file:

Re: Looking for something similar to Python's bisect_right

2013-10-30 Thread qznc
On Wednesday, 30 October 2013 at 18:56:42 UTC, Zeke wrote: On Wednesday, 30 October 2013 at 14:17:22 UTC, qznc wrote: Why do you want to find the exact prime first? Just check against sqrt(num) in the loop. auto upper = cast(ulong)sqrt(cast(double)num)) + 1; foreach(ulong prime; primes) { if

Re: Set variable at compile time

2013-10-30 Thread Ali Çehreli
On 10/30/2013 01:11 PM, Craig Dillabaugh wrote: I am writing code that uses a structure containing an array of points where the points may be of arbitrary dimension (though generally small). I would like to be able to pass the point dimension to my structure as a template parameter. struct

Re: Set variable at compile time

2013-10-30 Thread Craig Dillabaugh
On Wednesday, 30 October 2013 at 20:19:11 UTC, Adam D. Ruppe wrote: It won't really work on the command line alone, but the way I do it is a two step thing. First, make the thing use a config module: import myproject.config; alias Thing Thing_Impl!dim; then you go ahead and use Thing, which

Re: std.range.chunk without length

2013-10-30 Thread qznc
On Wednesday, 30 October 2013 at 00:20:12 UTC, Stephan Schiffels wrote: Hi, I'd like a version of std.range.chunk that does not require the range to have the length property. As an example, consider a file that you would like parse by lines and always lump together four lines, i.e. import

Re: Set variable at compile time

2013-10-30 Thread Craig Dillabaugh
On Wednesday, 30 October 2013 at 20:23:58 UTC, Ali Çehreli wrote: On 10/30/2013 01:11 PM, Craig Dillabaugh wrote: I am writing code that uses a structure containing an array of points where the points may be of arbitrary dimension (though generally small). I would like to be able to pass

Dynamic load from another context

2013-10-30 Thread Wolftein
I'm trying to design a plug-in system for my game, and i would like to share static members from both context (Application, Shared Library). I found out that i can get the address of a __gshared at compile time, so my question is, is it possible to build an associative array at compile-time?

Error when trying to compile with --profile.

2013-10-30 Thread Wolftein
Using --debug or --release works fine. But when i use --profile i get: c:\Program Files (x86)\DLang\dmd2\windows\bin\..\..\src\phobos\std\path.d(2187): Error: balancedParens is not nothrow c:\Program Files (x86)\DLang\dmd2\windows\bin\..\..\src\phobos\std\path.d(2188): Error: