Re: Implementing Haskell's Type-Level Quicksort in D

2014-02-14 Thread bearophile
Philippe Sigaud: So yes, D does not have Haskell nice syntax for pattern matching. I'd like some of such syntax for templates (and a little different syntax added to match structs inside switch statements: https://d.puremagic.com/issues/show_bug.cgi?id=596 ). Bye, bearophile

Re: how to iterate over an AA by key-value pair (tuple)?

2014-02-14 Thread bearophile
Timothee Cour: auto byKeyValue(){...} It's probably better to call the method byPair that is shorter. If I/someone does it, will it be merged in? Some people want those pairs to be tuples. But D lacks built-in tuples, so you need to use typecons ones. But to use the typecons ones you

Re: how to iterate over an AA by key-value pair (tuple)?

2014-02-14 Thread Jakob Ovrum
On Friday, 14 February 2014 at 07:35:34 UTC, Timothee Cour wrote: That seems like a worthy enhancement. If I/someone does it, will it be merged in? I really want it to happen, but I also want it to happen right. See the relevant pull request[1]. [1]

Re: Ranges, constantly frustrating

2014-02-14 Thread Regan Heath
On Fri, 14 Feb 2014 02:48:51 -, Jesse Phillips jesse.k.phillip...@gmail.com wrote: On Thursday, 13 February 2014 at 14:30:41 UTC, Regan Heath wrote: Don't get me wrong, counting the elements as you iterate over them is useful, but it isn't the index into the range you're likely after.

Re: Ranges, constantly frustrating

2014-02-14 Thread Jakob Ovrum
On Friday, 14 February 2014 at 12:10:51 UTC, Regan Heath wrote: FWIW I disagree. I think it's immediately and intuitively obvious what 'i' should be when you're foreaching over X items taken from another range, even if you do not know take returns another range. Compare it to calling a

inverse of escapeShellCommand?

2014-02-14 Thread Timothee Cour
is there a function to get the inverse of escapeShellCommand? ie: assert(escapeShellCommandInverse(` foo 'hello world' `)==[`foo`, `hello world`]);

Re: Ranges, constantly frustrating

2014-02-14 Thread bearophile
Regan Heath: FWIW I disagree. I think it's immediately and intuitively obvious what 'i' should be when you're foreaching over X items taken from another range, even if you do not know take returns another range. Compare it to calling a function on a range and foreaching on the result, you

Re: Implementing Haskell's Type-Level Quicksort in D

2014-02-14 Thread Meta
On Friday, 14 February 2014 at 06:05:08 UTC, Philippe Sigaud wrote: `alias` is just a bit of syntax sugar, it does not (at least for 2.064) have the same power than fully defining a template and the `is(...)` expression. Right. What I was saying, however, is it is strange to me that this

Re: Implementing Haskell's Type-Level Quicksort in D

2014-02-14 Thread bearophile
Meta: While it is heavier than Haskell's syntax, I have been consistently and pleasantly surprised by how powerful D's template pattern matching is (bugs notwithstanding). I wonder how well-known this is outside this mailing list... I keep reading blog posts that use Haskell and present

Optimize my code =)

2014-02-14 Thread Robin
Hiho, I am fairly new to the D programming and still reading throught the awesome online book at http://ddili.org/ders/d.en/index.html. However, I think it is missing some things or I am missing glasses and overlooked these parts in the book.^^ Currently I am trying to write a very simple

Re: Optimize my code =)

2014-02-14 Thread Craig Dillabaugh
On Friday, 14 February 2014 at 16:00:09 UTC, Robin wrote: this(size_t rows, size_t cols) { this.dim = Dimension(rows, cols); this.data = new T[this.dim.size]; enum nil = to!T(0); foreach(ref T element; this.data) element = nil; } I am no expert at optimizing D

Re: Optimize my code =)

2014-02-14 Thread John Colvin
On Friday, 14 February 2014 at 16:40:31 UTC, Craig Dillabaugh wrote: On Friday, 14 February 2014 at 16:00:09 UTC, Robin wrote: this(size_t rows, size_t cols) { this.dim = Dimension(rows, cols); this.data = new T[this.dim.size]; enum nil = to!T(0); foreach(ref T

Re: Optimize my code =)

2014-02-14 Thread bearophile
Robin: class Matrix(T = double) { private T[] data; private Dimension dim; } Also try final class or struct in your benchmark. And try to use ldc2 compiler for performance benchmarks. Perhaps dim is better const, unless you want to change the shape of the matrix.

Re: Optimize my code =)

2014-02-14 Thread bearophile
Craig Dillabaugh: this.data = new T[this.dim.size]; with: this.data.length = this.dim.size It's the same thing. Bye, bearophile

Re: Ranges, constantly frustrating

2014-02-14 Thread Regan Heath
On Fri, 14 Feb 2014 13:14:51 -, bearophile bearophileh...@lycos.com wrote: Regan Heath: FWIW I disagree. I think it's immediately and intuitively obvious what 'i' should be when you're foreaching over X items taken from another range, even if you do not know take returns another

Re: Ranges, constantly frustrating

2014-02-14 Thread Regan Heath
On Fri, 14 Feb 2014 12:29:49 -, Jakob Ovrum jakobov...@gmail.com wrote: On Friday, 14 February 2014 at 12:10:51 UTC, Regan Heath wrote: FWIW I disagree. I think it's immediately and intuitively obvious what 'i' should be when you're foreaching over X items taken from another range,

Re: Optimize my code =)

2014-02-14 Thread Craig Dillabaugh
On Friday, 14 February 2014 at 16:47:32 UTC, John Colvin wrote: On Friday, 14 February 2014 at 16:40:31 UTC, Craig Dillabaugh wrote: On Friday, 14 February 2014 at 16:00:09 UTC, Robin wrote: this(size_t rows, size_t cols) { this.dim = Dimension(rows, cols); this.data = new

Re: Optimize my code =)

2014-02-14 Thread Chris Cain
On Friday, 14 February 2014 at 16:00:09 UTC, Robin wrote: This is my class with its templated data as a one dimensional array (as I don't like jagged-arrays) and a dimension (which is a struct). The dimension object has some util functionality such as getting the total size or mapping (row,

Re: Ranges, constantly frustrating

2014-02-14 Thread bearophile
Regan Heath: In my case I didn't need any of these. I don't understand. Bye, bearophile

Re: Ranges, constantly frustrating

2014-02-14 Thread bearophile
Isn't this discussion about adding an index to a range? If it is, then I have shown why adding it in the language is a bad idea. Bye, bearophile

Re: Optimize my code =)

2014-02-14 Thread bearophile
Chris Cain: http://dlang.org/phobos/std_array.html#.uninitializedArray minimallyInitializedArray should be used, because it's safer. Bye, bearophile

Re: Optimize my code =)

2014-02-14 Thread thedeemon
On Friday, 14 February 2014 at 16:00:09 UTC, Robin wrote: class Matrix(T = double) { T opIndex(size_t row, size_t col) const { First of all make sure you it's not virtual, otherwise each element access will cost you enough to make it 10x slower than Java.

Re: Optimize my code =)

2014-02-14 Thread Xinok
On Friday, 14 February 2014 at 16:56:29 UTC, bearophile wrote: Craig Dillabaugh: this.data = new T[this.dim.size]; with: this.data.length = this.dim.size It's the same thing. Bye, bearophile Not quite. Setting length will copy over the existing contents of the array. Using new

Re: Optimize my code =)

2014-02-14 Thread Kapps
On Friday, 14 February 2014 at 16:00:09 UTC, Robin wrote: As I am very new to D I instantly ran into certain optimizing issues. E.g. the simple matrix multiplication based in my java implementation requires about 1.5 secs for multiplying two 1000x1000 matrices, however my D implementation

Reading input from piped stdin.

2014-02-14 Thread Thomas
I'm new to D, and I find it quite enjoyable so far. I have however stumbled upon a problem which I can't seem to figure out. I am trying to make a program that creates a child process, writes something to the child process stdin and reading from its stdout. I am going to use it later for testing

Re: Implementing Haskell's Type-Level Quicksort in D

2014-02-14 Thread Philippe Sigaud
On Fri, Feb 14, 2014 at 3:24 PM, bearophile bearophileh...@lycos.com wrote: Meta: While it is heavier than Haskell's syntax, I have been consistently and pleasantly surprised by how powerful D's template pattern matching is (bugs notwithstanding). I wonder how well-known this is outside this

Re: Reading input from piped stdin.

2014-02-14 Thread Adam D. Ruppe
Just a quick look, but I betcha it has to do with buffering. After writing the line to the pipe, call the flush() method on the output pipe and see what happens there. (Pipes buffer differently than regular output so this is a common mixup, especially with IDEs which communicate with stdout

Re: Reading input from piped stdin.

2014-02-14 Thread nazriel
On Friday, 14 February 2014 at 19:05:02 UTC, Thomas wrote: I'm new to D, and I find it quite enjoyable so far. I have however stumbled upon a problem which I can't seem to figure out. I am trying to make a program that creates a child process, writes something to the child process stdin and

Re: Reading input from piped stdin.

2014-02-14 Thread Steven Schveighoffer
On Fri, 14 Feb 2014 14:05:01 -0500, Thomas sitronv...@gmail.com wrote: I'm new to D, and I find it quite enjoyable so far. I have however stumbled upon a problem which I can't seem to figure out. I am trying to make a program that creates a child process, writes something to the child process

Re: Reading input from piped stdin.

2014-02-14 Thread nazriel
On Friday, 14 February 2014 at 19:09:06 UTC, nazriel wrote: On Friday, 14 February 2014 at 19:05:02 UTC, Thomas wrote: I'm new to D, and I find it quite enjoyable so far. I have however stumbled upon a problem which I can't seem to figure out. I am trying to make a program that creates a child

Re: Reading input from piped stdin.

2014-02-14 Thread Thomas
On Friday, 14 February 2014 at 19:08:20 UTC, Adam D. Ruppe wrote: Just a quick look, but I betcha it has to do with buffering. After writing the line to the pipe, call the flush() method on the output pipe and see what happens there. (Pipes buffer differently than regular output so this is a

Re: Reading input from piped stdin.

2014-02-14 Thread Steven Schveighoffer
On Fri, 14 Feb 2014 14:16:23 -0500, Thomas sitronv...@gmail.com wrote: On Friday, 14 February 2014 at 19:08:20 UTC, Adam D. Ruppe wrote: Just a quick look, but I betcha it has to do with buffering. After writing the line to the pipe, call the flush() method on the output pipe and see what

Re: Reading input from piped stdin.

2014-02-14 Thread Thomas
On Friday, 14 February 2014 at 19:12:24 UTC, Steven Schveighoffer wrote: On Fri, 14 Feb 2014 14:05:01 -0500, Thomas sitronv...@gmail.com wrote: I'm new to D, and I find it quite enjoyable so far. I have however stumbled upon a problem which I can't seem to figure out. I am trying to make a

DGUI

2014-02-14 Thread Josh Phillips
I recently downloaded and tried to use DGUI but I can't get it to work. Is there any tutorials on how to build an use it? Or can anyone help me and tel me a way on how I can get it to work?

Re: DGUI

2014-02-14 Thread Jeremy DeHaan
On Friday, 14 February 2014 at 20:29:50 UTC, Josh Phillips wrote: I recently downloaded and tried to use DGUI but I can't get it to work. Is there any tutorials on how to build an use it? Or can anyone help me and tel me a way on how I can get it to work? Unless I am mistaken, it looks like

Re: Ranges, constantly frustrating

2014-02-14 Thread Marc Schütz
On Friday, 14 February 2014 at 17:42:53 UTC, bearophile wrote: Isn't this discussion about adding an index to a range? If it is, then I have shown why adding it in the language is a bad idea. As far as I understand it, it's about adding an index to _foreach_, as is already supported for

Re: how to round durations to most significant unit ? (5 secs, 889 ms, and 811 μs = 5 secs)

2014-02-14 Thread Jonathan M Davis
On Thursday, February 13, 2014 23:37:13 Timothee Cour wrote: Is there a function to do this? If not and I/someone writes it, is there interest to add it to std.datetime? Duration t = ...; t.to!string = 5 secs, 889 ms, and 811 μs t.round.to!string= 5 secs t=...; t.to!string = 889 ms,

Re: Optimize my code =)

2014-02-14 Thread Nick Sabalausky
On 2/14/2014 11:00 AM, Robin wrote: class Matrix(T = double) { private T[] data; private Dimension dim; } A matrix is just plain-old-data, so use a struct, you don't need a class. A struct will be much more lightweight: A struct doesn't normally involve memory allocations like a

Re: Optimize my code =)

2014-02-14 Thread bearophile
Nick Sabalausky: T opIndex(size_t row, size_t col) const { immutable size_t i = this.dim.offset(row, col); if (i = this.dim.size) { // TODO - have to learn exception handling in D first. :P } return this.data[i]; } No need for the bounds check. D already does bounds

Re: Ranges, constantly frustrating

2014-02-14 Thread bearophile
Marc Schütz: As far as I understand it, it's about adding an index to _foreach_, as is already supported for arrays: foreach(v; [1,2,3,4]) writeln(v); foreach(i, v; [1,2,3,4]) writeln(i, = , v); But for ranges, the second form is not possible: foreach(v; iota(4)) // ok

Re: how to round durations to most significant unit ? (5 secs, 889 ms, and 811 μs = 5 secs)

2014-02-14 Thread Timothee Cour
thanks! On Fri, Feb 14, 2014 at 2:14 PM, Jonathan M Davis jmdavisp...@gmx.comwrote: On Thursday, February 13, 2014 23:37:13 Timothee Cour wrote: Is there a function to do this? If not and I/someone writes it, is there interest to add it to std.datetime? Duration t = ...; t.to!string

Floating point init/nan

2014-02-14 Thread Adam S
I seem to be having some difficulty with the nan and init properties of floating point types. Can anyone explain why the following assertions all fail: assert(float.init == float.nan); assert(float.nan == float.nan); assert(float.init == float.init); Thanks.

Re: Floating point init/nan

2014-02-14 Thread Adam D. Ruppe
On Saturday, 15 February 2014 at 05:18:51 UTC, Adam S wrote: assert(float.init == float.nan); nan never equals nan, this is in the floating point spec used by D, C and others. Use this instead: http://dlang.org/phobos/std_math.html#isNaN

Re: Floating point init/nan

2014-02-14 Thread bearophile
Adam D. Ruppe: nan never equals nan, Additionally, the init NaN doesn't have the same bitpattern as the other. There are many NaNs. Bye, bearophile

Re: Getting and using class hierarhy information in runtime

2014-02-14 Thread Uranuz
Also I have the following code but I get some error. I think it's because of std.algorithm.sort function that uses mixin to inject predcate. But it doesn't import symbols passed in predicate and fails. Is there some way of resolving this problem or I need to inject full code of function inside

Re: Getting and using class hierarhy information in runtime

2014-02-14 Thread Uranuz
I solved it myself. I forget that I can use function as predicate import std.stdio, std.algorithm; class A: Exception { this(){ super(null); } } class B: A {} class C: B {} class D: A {} class E: A {} class F: E {} size_t countDerivations(TypeInfo_Class typeinfo) { size_t