Re: Function to print a diamond shape

2014-03-25 Thread Jay Norwood
This corrects the parallel example range in the second foreach. Still slow. void printDiamonde2cpa(in uint N) { size_t N2 = N/2; char p[] = uninitializedArray!(char[])(N2+N); p[0..N2] = ' '; p[N2..$] = '*'; char nl[] = uninitializedArray!(char[])(1); nl[] = '\n'; ch

Re: Function to print a diamond shape

2014-03-25 Thread Jay Norwood
On Wednesday, 26 March 2014 at 04:47:48 UTC, Jay Norwood wrote: This is a first attempt at using parallel, but no improvement oops. scratch that one. I tested a pointer to the wrong function.

Re: Function to print a diamond shape

2014-03-25 Thread Jay Norwood
This is a first attempt at using parallel, but no improvement in speed on a corei7. It is about 3x slower than the prior versions. Probably the join was not a good idea. Also, no foreach_reverse for the parallel, so it requires extra calculations for the reverse index. void printDiamonde2

Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread Steven Schveighoffer
On Tue, 25 Mar 2014 19:13:07 -0400, H. S. Teoh wrote: On Tue, Mar 25, 2014 at 10:02:33PM +, monarch_dodra wrote: On Tuesday, 25 March 2014 at 21:35:47 UTC, Mark Isaacson wrote: >Is there a performance benefit? Is it simply because it's more general? [...] There is *1* thing you should

Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread H. S. Teoh
On Tue, Mar 25, 2014 at 10:02:33PM +, monarch_dodra wrote: > On Tuesday, 25 March 2014 at 21:35:47 UTC, Mark Isaacson wrote: > >Is there a performance benefit? Is it simply because it's more general? [...] > There is *1* thing you should take into account though: "to!" is a > no-op for string=>

Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread Mark Isaacson
Much appreciated everyone! I had a vague intuition that these were the reasons, but it was helpful to spell them out. I'm especially partial to the self-documentation reasoning.

Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread monarch_dodra
On Tuesday, 25 March 2014 at 21:35:47 UTC, Mark Isaacson wrote: Is there a performance benefit? Is it simply because it's more general? Mostly because it's more generic. For example: If instead you want to do "string" => "char[]", then your code will have to be changed to use "dup". if instead

Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread bearophile
Mark Isaacson: why use `to!string` instead of just doing `line[2 .. $].idup`? I sometimes prefer the text function: = line[2 .. $].text; Bye, bearophile

Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread Justin Whear
On Tue, 25 Mar 2014 21:35:46 +, Mark Isaacson wrote: > I am presently working my way through TDPL for the second time, and > there's an example in chapter 1 to the effect of: > > [code] > string currentParagraph; > foreach(line; stdin.byLine()) { >if (line.length > 2) { > currentPara

[Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread Mark Isaacson
I am presently working my way through TDPL for the second time, and there's an example in chapter 1 to the effect of: [code] string currentParagraph; foreach(line; stdin.byLine()) { if (line.length > 2) { currentParagraph = to!string(line[2 .. $]); } } [/code] The explicit conversion

Re: Problem with taking inout, const references

2014-03-25 Thread Ali Çehreli
On 03/25/2014 02:01 PM, Uranuz wrote: >> Your code compiles with the development branch of dmd. What version >> are you using? >> > Now I'm using 2.064. Still compiles for me. Could you please show us a minimal main() as well. Thank you, Ali

Re: Musings on infinite loops and not reachable returns

2014-03-25 Thread bearophile
anonymous: When you know that it won't be reached, you can (should?) put assert(false) instead of a return. Yes, right, I use assert(false) in those cases :-) Bye, bearophile

Re: Problem with @safe

2014-03-25 Thread Atila Neves
Sigh. I figured out what was going on. The reason why the compiler never complained and the intended function never got called is because I had a static if checking for __traits(compiles, ...). The attributes made sense, but _I_ was silencing the compiler. Ugh. Atila On Tuesday, 25 March 2014

Re: Musings on infinite loops and not reachable returns

2014-03-25 Thread monarch_dodra
On Tuesday, 25 March 2014 at 20:49:57 UTC, bearophile wrote: This code compiles with no errors or warnings: struct Foo { int opApply(int delegate(ref ubyte) dg) { int result; ubyte x; while (true) { result = dg(x); if (result) return result;

Re: Musings on infinite loops and not reachable returns

2014-03-25 Thread anonymous
On Tuesday, 25 March 2014 at 20:49:57 UTC, bearophile wrote: This code compiles with no errors or warnings: struct Foo { int opApply(int delegate(ref ubyte) dg) { int result; ubyte x; while (true) { result = dg(x); if (result) return result;

Re: Musings on infinite loops and not reachable returns

2014-03-25 Thread bearophile
Chris Williams: I'm not seeing it. "while (true)" is no more an infinite loop than "for (i = 0; i < x; i++)", if the body of the while has a break or return statement. I see, so there's nothing to improve here :-) Bye, bearophile

Re: Musings on infinite loops and not reachable returns

2014-03-25 Thread Chris Williams
On Tuesday, 25 March 2014 at 20:49:57 UTC, bearophile wrote: Note how the opApply() of Foo should not end with a return, while the opApply() of Bar is required by the D compiler to end with a return. Yet, Foo is contains an infinite loop, so the result of Bar will not be reached. But the type

Re: Problem with taking inout, const references

2014-03-25 Thread Uranuz
Your code compiles with the development branch of dmd. What version are you using? Now I'm using 2.064. May be this bug is already fixed. In 2.065 I experience problem that std.json library module is not compatible with code written for previous versions. This is why I returned to 2.064. As f

Musings on infinite loops and not reachable returns

2014-03-25 Thread bearophile
This code compiles with no errors or warnings: struct Foo { int opApply(int delegate(ref ubyte) dg) { int result; ubyte x; while (true) { result = dg(x); if (result) return result; x++; } //return result; // Warning:

Re: Compile time only delegates

2014-03-25 Thread Frustrated
On Tuesday, 25 March 2014 at 18:10:17 UTC, Meta wrote: On Tuesday, 25 March 2014 at 18:05:47 UTC, Frustrated wrote: Due to a previous issue I am trying to do the following mixin template A() { mixin((function () => "int x;")() ); } the problem is that the compiler will not let me use the d

Re: Compile time only delegates

2014-03-25 Thread Frustrated
On Tuesday, 25 March 2014 at 20:20:29 UTC, Frustrated wrote: On Tuesday, 25 March 2014 at 18:10:17 UTC, Meta wrote: On Tuesday, 25 March 2014 at 18:05:47 UTC, Frustrated wrote: Due to a previous issue I am trying to do the following mixin template A() { mixin((function () => "int x;")() ); }

Re: Problem with taking inout, const references

2014-03-25 Thread Ali Çehreli
On 03/25/2014 12:20 PM, Uranuz wrote: > I have problem with understanding of work of modifiers const, inout, > immutable modifiers. I am sure you know these as well, but here is my quick list: const: "I shall not modify data" immutable: "I demand immutable data" inout: "Whatever the actual type

Re: Function to print a diamond shape

2014-03-25 Thread Jay Norwood
On Tuesday, 25 March 2014 at 15:31:12 UTC, monarch_dodra wrote: I love how D can achieve *great* performance, while still looking readable and maintainable. Yes, I'm pretty happy to see the appender works well. The parallel library also seems to work very well in my few experiences with it.

Re: Compile time only delegates

2014-03-25 Thread Philippe Sigaud
This works for me (2.064): import std.stdio : writeln; void main() { mixin({ return "int x;"; }()); writeln(x); }

Problem with taking inout, const references

2014-03-25 Thread Uranuz
I have problem with understanding of work of modifiers const, inout, immutable modifiers. As I understand inout keyword is intended to consume const, immutable and data without modifiers. It's how I expect it to work otherwise I don't understand what is the purpose of inout. In current implemen

Re: Problem with @safe

2014-03-25 Thread Atila Neves
I probably should have mentioned that the bug is introduced in the parent commit. The code I originally wrote that triggered the bug was larger, of course. Replacing that parent commit with a call to writeln does the same thing. I would expect a compiler error instead. On Tuesday, 25 March 2

Re: Problem with @safe

2014-03-25 Thread Meta
On Tuesday, 25 March 2014 at 17:57:33 UTC, Atila Neves wrote: I just spent a lot of time trying to debug my code and it seems to have to do with @safe. I have some template functions in a class, and one of them, marked as @safe, ended up making a call to an abstract function with no attribute.

Re: Compile time only delegates

2014-03-25 Thread Meta
On Tuesday, 25 March 2014 at 18:05:47 UTC, Frustrated wrote: Due to a previous issue I am trying to do the following mixin template A() { mixin((function () => "int x;")() ); } the problem is that the compiler will not let me use the delegate because it has no this context. Of course the w

Compile time only delegates

2014-03-25 Thread Frustrated
Due to a previous issue I am trying to do the following mixin template A() { mixin((function () => "int x;")() ); } the problem is that the compiler will not let me use the delegate because it has no this context. Of course the whole point here is that the delegate will never be used at ru

Problem with @safe

2014-03-25 Thread Atila Neves
I just spent a lot of time trying to debug my code and it seems to have to do with @safe. I have some template functions in a class, and one of them, marked as @safe, ended up making a call to an abstract function with no attribute. My unit test started failing and I tried writeln-debugging but

Re: Exception "error" message without stacktrace

2014-03-25 Thread Spacen Jasset
I see thanks. I couldn't see the throwable class at the time.

Re: Function to print a diamond shape

2014-03-25 Thread monarch_dodra
On Tuesday, 25 March 2014 at 12:30:37 UTC, Jay Norwood wrote: These are times on ubuntu. printDiamond3 was slower than printDiamond. Hum... Too bad :/ I was able to improve my first "printDiamon" by having a single slice that contains spaces then stars, and make writeln's of that. It gave (

Re: Exception "error" message without stacktrace

2014-03-25 Thread bearophile
Spacen Jasset: I caught a FileException, and want to print out the descriptive error, but not the stacktrace. I cannot see how to do this at the moment. I only see the toString function. void main() { import std.stdio; try { File("hello"); } catch (Exception e) {

Re: Exception "error" message without stacktrace

2014-03-25 Thread David
Am 25.03.2014 15:43, schrieb Spacen Jasset: > I caught a FileException, and want to print out the descriptive error, > but not the stacktrace. I cannot see how to do this at the moment. I > only see the toString function. > > i.e. in the case below I would like to obtain "c:/temp\junk: The > direc

Re: Exception "error" message without stacktrace

2014-03-25 Thread Andrej Mitrovic
On Tuesday, 25 March 2014 at 14:43:18 UTC, Spacen Jasset wrote: I caught a FileException, and want to print out the descriptive error, but not the stacktrace. Try writing the exception's 'msg' field (it's a string). There is also 'file' and 'line'. See the class Throwable (in object.d or obje

Exception "error" message without stacktrace

2014-03-25 Thread Spacen Jasset
I caught a FileException, and want to print out the descriptive error, but not the stacktrace. I cannot see how to do this at the moment. I only see the toString function. i.e. in the case below I would like to obtain "c:/temp\junk: The directory is not empty." or something similar, but not th

Re: CMake for D

2014-03-25 Thread Trent Forkert
On Tuesday, 25 March 2014 at 01:15:10 UTC, Trent Forkert wrote: On Monday, 24 March 2014 at 23:55:14 UTC, Dragos Carp wrote: Any alternatives?? I moved cmaked2 to github [1], updated and simplified the usage a little (system cmake patch not necessary anymore). You can give it a try. Dub reg

Re: How useful should inout be?

2014-03-25 Thread Kagamin
* for function parameters

Re: How useful should inout be?

2014-03-25 Thread Kagamin
On Sunday, 23 March 2014 at 10:28:54 UTC, Infiltrator wrote: So, is this a limitation with inout, part of its design, or am I misunderstaning something more fundamental? It's fundamental: inout makes sense for function attributes only and can't be used as a template parameter or struct/class f

Re: Function to print a diamond shape

2014-03-25 Thread Jay Norwood
These are times on ubuntu. printDiamond3 was slower than printDiamond. brad: time: 12387[ms] printDiamond1: time: 373[ms] printDiamond2: time: 722[ms] printDiamond3: time: 384[ms] jay1: time: 62[ms] sergei: time: 3918[ms] jay2: time: 28[ms] diamondShape: time: 2725[ms] printDiamond: time: 19[ms

DGUI: Using scroll bars

2014-03-25 Thread Mike James
I'm using DGUI (the one on bitbucket) and I can't work out how to use the scrollbars. I've got them enabled but I can't work out from the library files how to set the scale and read the position. Also is there a way of turning off the vertical scrollbar - the 'enable' turns them both on. Any

Re: Function to print a diamond shape

2014-03-25 Thread Jay Norwood
Interesting. I'd have thought the "extra copy" would be an overall slowdown, but I guess that's not the case. I also tried your strategy of adding '\n' to the buffer, but I was getting some bad output on windows. I'm not sure why "\n\n" works though. On *nix, I'd have also expected a doub

Re: Function to print a diamond shape

2014-03-25 Thread monarch_dodra
On Tuesday, 25 March 2014 at 02:25:57 UTC, Jay Norwood wrote: not through yet with the diamond. This one is a little faster. Appending the newline to the stars and calculating the slice backward from the end would save a w.put for the newlines ... probably faster. I keep looking for a way to

Re: Installing D on OSX using .dmg

2014-03-25 Thread Joel
On Monday, 17 March 2014 at 13:09:29 UTC, Russel Winder wrote: On Sun, 2014-03-16 at 23:10 +, Joel wrote: Thanks Russel! I've gotten past the security problem! There's options under Security & Privacy (and what can be downloaded): O-MacApp Store O-idetinified developers @-Anywhere. Tho