Formatted input from text file

2012-06-18 Thread IK
I'm attempting Project Euler's problem 11. http://projecteuler.net/problem=11 Currently, my code looks like posted below, and it gives object.Error: Access Violation at runtime. Question: how to read that grid from a text file? (See link above.) If you have ideas for using something other

Re: Formatted input from text file

2012-06-18 Thread bearophile
IK: Question: how to read that grid from a text file? I don't know the cause of your problem. While investigating it I have filed another bug: http://d.puremagic.com/issues/show_bug.cgi?id=8260 In the meantime this (a bit scary) code solves your reading problem: import std.stdio,

Re: sorting associative array's keys by values

2012-06-18 Thread maarten van damme
Everything turned out to be problems with \r \n. The treading system worked perfectly (although I still don't understand how one can use immutable and receiveonly).

Re: sorting associative array's keys by values

2012-06-18 Thread maarten van damme
and something I forgot to ask, is it a conscious decision to not print out fired asserts in treads? Normally when an assert fails my whole program crashes and I can see what went wrong. With treads however, it quietly dies.

Re: Formatted input from text file

2012-06-18 Thread IK
Hmm does your code generate a 1D `array` as a grid, bearophile? Anyway thanks, I'll compile it shortly. My own code evolved to what's below and gives a Range violation. Also I don't understand why formattedRead can't just accept a casted `opSlice.dup`, is it a bug? void main() {

Re: Simulating rectangular array

2012-06-18 Thread Andrej Mitrovic
On 6/17/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: Has anyone come up with a template that can simulate a rectangular array and allow one to override opAssign to do special work? Thanks for the replies, guys.

Re: Idiomatic D?

2012-06-18 Thread Matt Diesel
Sorry, forgot to post the code: http://pastie.org/4109337 Is there no way to edit posts?

Idiomatic D?

2012-06-18 Thread Matt Diesel
Today I learnt D. I have a lot of experience with other languages, but I think D fills a gap. So far I've really liked it, having used C# and C a lot it feels right. I'm also pretty excited about some of the more powerful features. I can teach myself a language no problem, but to make it

Why doesn't alias this work with arrays?

2012-06-18 Thread Andrej Mitrovic
struct Wrap { string wrap; alias wrap this; } void main() { Wrap x; x = foo; // ok Wrap[] y = [foo, bar]; // fail } Error: cannot implicitly convert expression ([foo,bar]) of type string[] to Wrap[] Any special reason why this doesn't work? I hope it's just a bug or

Re: Why doesn't alias this work with arrays?

2012-06-18 Thread Jonathan M Davis
On Monday, June 18, 2012 18:51:01 Andrej Mitrovic wrote: struct Wrap { string wrap; alias wrap this; } void main() { Wrap x; x = foo; // ok Wrap[] y = [foo, bar]; // fail } Error: cannot implicitly convert expression ([foo,bar]) of type string[] to Wrap[] Any special reason why

Re: Idiomatic D?

2012-06-18 Thread bearophile
Matt Diesel: Firstly, is there any good resource on what idiomatic D usage is? For instance Go has a huge page called Effective Go which tells you how you should use features, rather than what they are. I don't know any such page, but it looks like an interesting addition for the online

Re: Idiomatic D?

2012-06-18 Thread Justin Whear
On Mon, 18 Jun 2012 18:22:34 +0200, Matt Diesel wrote: Sorry, forgot to post the code: http://pastie.org/4109337 Is there no way to edit posts? A couple of observations: - According to the D style guide (http://dlang.org/dstyle.html), you should prefer to capitalize class and struct

Re: Why doesn't alias this work with arrays?

2012-06-18 Thread Andrej Mitrovic
On 6/18/12, Jonathan M Davis jmdavisp...@gmx.com wrote: At that point, you'd need to be converting from string[] to Wrap[], which would mean creating a new array It doesn't have to allocate anything because there's the 'alias this' and a single data member. All the compiler has to do is cast

Re: Why doesn't alias this work with arrays?

2012-06-18 Thread Jonathan M Davis
On Monday, June 18, 2012 19:05:35 Andrej Mitrovic wrote: On 6/18/12, Jonathan M Davis jmdavisp...@gmx.com wrote: At that point, you'd need to be converting from string[] to Wrap[], which would mean creating a new array It doesn't have to allocate anything because there's the 'alias this'

Re: Idiomatic D?

2012-06-18 Thread Matt Diesel
Thanks to both of you, that was exactly the sort of input I was looking for :) The D Style guide looks like what I wanted. It's more just about formatting but that should be enough for now. I can't really reply to each individual point, but there is a lot of new stuff there that at first

Re: Idiomatic D?

2012-06-18 Thread Jonathan M Davis
On Monday, June 18, 2012 18:20:58 Matt Diesel wrote: Today I learnt D. I have a lot of experience with other languages, but I think D fills a gap. So far I've really liked it, having used C# and C a lot it feels right. I'm also pretty excited about some of the more powerful features. I can

Re: Swap furthest element type of an array

2012-06-18 Thread Timon Gehr
On 06/18/2012 06:29 PM, Andrej Mitrovic wrote: I just had a need for this but couldn't find it in Phobos: import std.stdio; import std.traits; import std.range; template SwapElem(Arr, Type) { static if (isArray!(ElementType!Arr)) { static if (isDynamicArray!Arr)

Re: sorting associative array's keys by values

2012-06-18 Thread Era Scarecrow
On Monday, 18 June 2012 at 13:22:24 UTC, maarten van damme wrote: and something I forgot to ask, is it a conscious decision to not print out fired asserts in treads? Normally when an assert fails my whole program crashes and I can see what went wrong. With treads however, it quietly dies.

Small code review

2012-06-18 Thread mist
Subj: http://dpaste.dzfl.pl/dfab7219 I wanted to code a small extension to phobos typetuple module to extend basic available operations on type tuples more on par with std.algorithm ones. I don't have enough practice in metaprogramming D way though and would gladly listen any recommendations

Re: Swap furthest element type of an array

2012-06-18 Thread Andrej Mitrovic
On 6/18/12, Timon Gehr timon.g...@gmx.ch wrote: template SwapElem(A, E){ static if(is(A X:X[N],size_t N)) alias SwapElem!(X,E)[N] R; else static if(is(A X:X[])) alias SwapElem!(X,E)[] R; else static if(is(A X:X*)) alias SwapElem!(X,E)* R; else alias E R; alias R

Re: Small code review

2012-06-18 Thread Jonathan M Davis
On Monday, June 18, 2012 23:41:01 mist wrote: Subj: http://dpaste.dzfl.pl/dfab7219 I wanted to code a small extension to phobos typetuple module to extend basic available operations on type tuples more on par with std.algorithm ones. I don't have enough practice in metaprogramming D way

Re: Swap furthest element type of an array

2012-06-18 Thread Timon Gehr
On 06/19/2012 12:01 AM, Andrej Mitrovic wrote: On 6/18/12, Timon Gehrtimon.g...@gmx.ch wrote: template SwapElem(A, E){ static if(is(A X:X[N],size_t N)) alias SwapElem!(X,E)[N] R; else static if(is(A X:X[])) alias SwapElem!(X,E)[] R; else static if(is(A X:X*)) alias

Re: Swap furthest element type of an array

2012-06-18 Thread Andrej Mitrovic
On 6/19/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: On 6/19/12, Timon Gehr timon.g...@gmx.ch wrote: Indeed. If you are interested, I'll make it work with qualified types as well. =) I thought it already does? Oh you meant to *keep* the qualifier, yeah.

Re: Swap furthest element type of an array

2012-06-18 Thread Andrej Mitrovic
On 6/19/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: On 6/19/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: On 6/19/12, Timon Gehr timon.g...@gmx.ch wrote: Indeed. If you are interested, I'll make it work with qualified types as well. =) I thought it already does? Oh you

Re: Why doesn't alias this work with arrays?

2012-06-18 Thread Kenji Hara
On Monday, 18 June 2012 at 16:51:11 UTC, Andrej Mitrovic wrote: struct Wrap { string wrap; alias wrap this; } void main() { Wrap x; x = foo; // ok Wrap[] y = [foo, bar]; // fail } Error: cannot implicitly convert expression ([foo,bar]) of type string[] to Wrap[] Any