Auto return type inference issue?

2014-04-22 Thread Matthew Dudley via Digitalmars-d-learn
Here's the gist of what I'm trying to do. https://gist.github.com/pontifechs/11169069 I'm getting an error I don't understand: tinker.d(42): Error: mismatched function return type inference of tinker.B and tinker.A tinker.d(55): Error: template instance tinker.DynamicTuple!(A,

Re: Auto return type inference issue?

2014-04-22 Thread bearophile via Digitalmars-d-learn
Matthew Dudley: Also, as an aside, why can't tuples be indexed dynamically? Most of my problems with this have been because you apparently can't. Think about how D tuples are implemented, they are essentially structs. Every tuple element can have a different type and to be represented in

Throw exception on segmentation fault in GNU/Linux

2014-04-22 Thread ilya-stromberg via Digitalmars-d-learn
What should I add in the D program in GNU/Linux to throw exception if I have segmentation fault error? I read somewhere that it's possible, but I don't know how to do it.

Re: Function to print a diamond shape

2014-04-22 Thread Jay Norwood via Digitalmars-d-learn
Wow, joiner is much slower than join. Such a small choice can make this big of a difference. Not at all expected, since the lazy calls, I thought, were considered to be more efficient. This is with ldc2 -O2. jay@jay-ubuntu:~/ec_ddt/workspace/diamond/source$ ./main 1/dev/null brad: time:

Re: Best way to check for an element in an array?

2014-04-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On Mon, 21 Apr 2014 23:25:39 -0400, Taylor Hillegeist taylorh...@gmail.com wrote: So I find myself Doing this kind of thing very frequently. I have a Array of Somethings and i want to see if something specific is inside the array. I wrote a template for it. but is this the best way to do

Named template constraints

2014-04-22 Thread Tim Holzschuh via Digitalmars-d-learn
Hi there, I recently read the 'More Templates' chapter of Ali's book (-- thanks for that ;) ). At the section 'Named constraints', there were a definition like this: template isUsable(T) { enum isUsable = is ( typeof( { T obj; obj.call(); obj.otherCall(1);

Re: Throw exception on segmentation fault in GNU/Linux

2014-04-22 Thread Kagamin via Digitalmars-d-learn
You should write and register a signal handler. Implementation for x86-32 was posted here.

Re: Throw exception on segmentation fault in GNU/Linux

2014-04-22 Thread Dicebot via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 09:58:45 UTC, ilya-stromberg wrote: What should I add in the D program in GNU/Linux to throw exception if I have segmentation fault error? I read somewhere that it's possible, but I don't know how to do it. etc.linux.memoryerror Just remember that it is more of

Re: Named template constraints

2014-04-22 Thread Andrej Mitrovic via Digitalmars-d-learn
On 4/22/14, Tim Holzschuh via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: What does (inout int = 0) mean/affect here? This was asked recently, see my reponse here: http://forum.dlang.org/post/mailman.102.1396007039.25518.digitalmars-d-le...@puremagic.com

Re: Named template constraints

2014-04-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tue, 22 Apr 2014 10:58:41 -0400, Andrej Mitrovic via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On 4/22/14, Tim Holzschuh via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: What does (inout int = 0) mean/affect here? This was asked recently, see my

Re: Named template constraints

2014-04-22 Thread Hannes Steffenhagen via Digitalmars-d-learn
Not sure what InputRange is defined as atm, but I don't think anything should have to define init to be a valid inputrange.

Array of interface only with cast()?

2014-04-22 Thread Andre via Digitalmars-d-learn
Hi, I just stumbled about this issue with array of interface. I want to pass several objects (C and D) which shares the same interface A. It seems somehow cumbersome that it only works if there is a cast on the first element of the array. interface A{} class B: A{} class C: B{}; class D: B{};

Re: Named template constraints

2014-04-22 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 15:06:34 UTC, Steven Schveighoffer wrote: Note, is the r2 = R.init needed? Not sure. Yes: It R2 has no default init, or is an immutable, then that line will fail to compile.

Re: Array of interface only with cast()?

2014-04-22 Thread Andrej Mitrovic via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 15:19:55 UTC, Andre wrote: Is the cast really needed? It's a known issue and a filed bug report. I don't have the Issue number at hand though, someone else will likely provide it.

Re: Function to print a diamond shape

2014-04-22 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 05:05:30 UTC, Jay Norwood wrote: On Monday, 21 April 2014 at 08:26:49 UTC, monarch_dodra wrote: The two key points here, first, is to avoid using appender. Second, instead of having two buffer: and **\n, and two do two slice copies, to only have 1 buffer

Re: Array of interface only with cast()?

2014-04-22 Thread Andre via Digitalmars-d-learn
Am 22.04.2014 17:23, schrieb Andrej Mitrovic: On Tuesday, 22 April 2014 at 15:19:55 UTC, Andre wrote: Is the cast really needed? It's a known issue and a filed bug report. I don't have the Issue number at hand though, someone else will likely provide it. Nice to hear that it is not by

Re: Function to print a diamond shape

2014-04-22 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 11:41:41 UTC, Jay Norwood wrote: Wow, joiner is much slower than join. Such a small choice can make this big of a difference. Not at all expected, since the lazy calls, I thought, were considered to be more efficient. This is with ldc2 -O2. Yeah, that's

Re: Named template constraints

2014-04-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tue, 22 Apr 2014 11:15:14 -0400, monarch_dodra monarchdo...@gmail.com wrote: On Tuesday, 22 April 2014 at 15:06:34 UTC, Steven Schveighoffer wrote: Note, is the r2 = R.init needed? Not sure. Yes: It R2 has no default init, or is an immutable, then that line will fail to compile. I

Re: Array of interface only with cast()?

2014-04-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tue, 22 Apr 2014 11:19:57 -0400, Andre an...@s-e-a-p.de wrote: Hi, I just stumbled about this issue with array of interface. I want to pass several objects (C and D) which shares the same interface A. It seems somehow cumbersome that it only works if there is a cast on the first element of

Re: Named template constraints

2014-04-22 Thread Andrej Mitrovic via Digitalmars-d-learn
On 4/22/14, Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn@puremagic.com I think this can be fixed a different way. Feel free to file a bug / make a pull. :

Re: Named template constraints

2014-04-22 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 15:30:36 UTC, Steven Schveighoffer wrote: On Tue, 22 Apr 2014 11:15:14 -0400, monarch_dodra monarchdo...@gmail.com wrote: On Tuesday, 22 April 2014 at 15:06:34 UTC, Steven Schveighoffer wrote: Note, is the r2 = R.init needed? Not sure. Yes: It R2 has no default

Re: Array of interface only with cast()?

2014-04-22 Thread bearophile via Digitalmars-d-learn
Andre: Nice to hear that it is not by design but will be fixed. See: https://issues.dlang.org/show_bug.cgi?id=3543 Bye, bearophile

Re: Throw exception on segmentation fault in GNU/Linux

2014-04-22 Thread ilya-stromberg via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 14:49:58 UTC, Dicebot wrote: On Tuesday, 22 April 2014 at 09:58:45 UTC, ilya-stromberg wrote: What should I add in the D program in GNU/Linux to throw exception if I have segmentation fault error? I read somewhere that it's possible, but I don't know how to do it.

Re: Throw exception on segmentation fault in GNU/Linux

2014-04-22 Thread Dicebot via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 15:47:37 UTC, ilya-stromberg wrote: On Tuesday, 22 April 2014 at 14:49:58 UTC, Dicebot wrote: On Tuesday, 22 April 2014 at 09:58:45 UTC, ilya-stromberg wrote: What should I add in the D program in GNU/Linux to throw exception if I have segmentation fault error? I

The lifetime of reduce's internal seed

2014-04-22 Thread Ali Çehreli via Digitalmars-d-learn
I opened the following bug before reading reduce's documentation carefully: https://issues.dlang.org/show_bug.cgi?id=12610 import std.stdio; import std.algorithm; void main() { int[] arr = [ 0 ]; int[1] seed; int[] result = reduce!((sum, _) = sum[])(seed, arr); writefln(%s,

Re: The lifetime of reduce's internal seed

2014-04-22 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 17:31:22 UTC, Ali Çehreli wrote: I opened the following bug before reading reduce's documentation carefully: https://issues.dlang.org/show_bug.cgi?id=12610 import std.stdio; import std.algorithm; void main() { int[] arr = [ 0 ]; int[1] seed; int[]

Re: Named template constraints

2014-04-22 Thread Ali Çehreli via Digitalmars-d-learn
On 04/22/2014 07:07 AM, Tim Holzschuh via Digitalmars-d-learn wrote: read the 'More Templates' chapter of Ali's book (-- thanks for that ;) ). Yay! :) At the section 'Named constraints', there were a definition like this: template isUsable(T) { enum isUsable = is ( typeof( {

Re: Named template constraints

2014-04-22 Thread Tim Holzschuh via Digitalmars-d-learn
Am 22.04.2014 16:58, schrieb Andrej Mitrovic via Digitalmars-d-learn: On 4/22/14, Tim Holzschuh via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: What does (inout int = 0) mean/affect here? This was asked recently, see my reponse here:

Re: The lifetime of reduce's internal seed

2014-04-22 Thread Ali Çehreli via Digitalmars-d-learn
On 04/22/2014 11:03 AM, monarch_dodra wrote: On Tuesday, 22 April 2014 at 17:31:22 UTC, Ali Çehreli wrote: I opened the following bug before reading reduce's documentation carefully: https://issues.dlang.org/show_bug.cgi?id=12610 import std.stdio; import std.algorithm; void main() {

Re: The lifetime of reduce's internal seed

2014-04-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tue, 22 Apr 2014 14:17:57 -0400, Ali Çehreli acehr...@yahoo.com wrote: I don't think there is slicing an rvalue though. (?) reduce() is taking a copy of the seed and then returning a slice to it because the user slices it in their lambda. It effectively does the following, which

Re: Named template constraints

2014-04-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tue, 22 Apr 2014 11:36:07 -0400, monarch_dodra monarchdo...@gmail.com wrote: On Tuesday, 22 April 2014 at 15:30:36 UTC, Steven Schveighoffer wrote: Also, an immutable can be initialized that way: immutable int[] = int[].init; Isn't that exactly R.init ? Yes, you said if it's an

Re: The lifetime of reduce's internal seed

2014-04-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tue, 22 Apr 2014 14:47:19 -0400, monarch_dodra monarchdo...@gmail.com wrote: In this case no, but; // int[1] foo(); int[] a = foo(); // *is* slicing an rvalue, and it *does* compile. I don't think there needs to be escape analysis to catch this. Oh yeah, that's bad. -Steve

Re: The lifetime of reduce's internal seed

2014-04-22 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 18:34:47 UTC, Steven Schveighoffer wrote: On Tue, 22 Apr 2014 14:17:57 -0400, Ali Çehreli acehr...@yahoo.com wrote: I don't think there is slicing an rvalue though. (?) reduce() is taking a copy of the seed and then returning a slice to it because the user slices

Re: Named template constraints

2014-04-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tue, 22 Apr 2014 14:50:44 -0400, monarch_dodra monarchdo...@gmail.com wrote: On Tuesday, 22 April 2014 at 18:35:58 UTC, Steven Schveighoffer wrote: On Tue, 22 Apr 2014 11:36:07 -0400, monarch_dodra monarchdo...@gmail.com wrote: On Tuesday, 22 April 2014 at 15:30:36 UTC, Steven

Variable Naming Issue (Conflicts?)

2014-04-22 Thread Casey via Digitalmars-d-learn
Hello, I'm working on some code where I'm trying to generate structs that map to JSON documents via a mixin. That part works except when specific variable gets created. Below is the error that I'm getting: source/objects.d-mixin-70(75): Error: no identifier for declarator string

Re: Variable Naming Issue (Conflicts?)

2014-04-22 Thread bearophile via Digitalmars-d-learn
Casey: My question is, is there a way I can prevent this conflict from occurring without affecting what the struct will look like? The usual strategy is to append an underscore. (I think C# uses a @ prefix). Bye, bearophile

Re: Variable Naming Issue (Conflicts?)

2014-04-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tue, 22 Apr 2014 15:35:33 -0400, Casey sybra...@gmail.com wrote: If I prefix all of the generated variables with an underscore, it works fine. It looks like the variable delete is the issue. To me, it looks like it's expecting some sort of delete method. delete is a keyword, it cannot

Re: Variable Naming Issue (Conflicts?)

2014-04-22 Thread Casey via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 19:38:09 UTC, bearophile wrote: Casey: My question is, is there a way I can prevent this conflict from occurring without affecting what the struct will look like? The usual strategy is to append an underscore. (I think C# uses a @ prefix). Bye, bearophile

Re: Variable Naming Issue (Conflicts?)

2014-04-22 Thread bearophile via Digitalmars-d-learn
Casey: I've done that, but then it changes the name which, from what I've read in the documentation, means the JSON - object conversion won't work since it won't see a variable named delete. Perhaps we need a built-in syntax solution as in C#, like a $delete. Bye, bearophile

Re: Variable Naming Issue (Conflicts?)

2014-04-22 Thread Casey via Digitalmars-d-learn
Perhaps we need a built-in syntax solution as in C#, like a $delete. So, two things: 1. I guess my current approach is screwed. I figured as much. 2. Seeing $delete makes me miss Perl/PHP variable naming. It is one extra character, but it did make them stand out more. Anyway, thanks.

Re: Auto return type inference issue?

2014-04-22 Thread Jesse Phillips via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 07:54:34 UTC, Matthew Dudley wrote: Here's the gist of what I'm trying to do. https://gist.github.com/pontifechs/11169069 I'm getting an error I don't understand: tinker.d(42): Error: mismatched function return type inference of tinker.B and tinker.A