Re: with(a,b,c, ...) blocks..

2012-10-17 Thread ixid
Theoretically legal... void func() //in/out contracts body with (E) { //with replaces normal block } This seems sensible. Multiple with seems like a recipe for confusion and member name clashes.

Re: How to define an interator to provide array like behaviour in a class?

2012-10-17 Thread Jacob Carlborg
On 2012-10-17 00:23, Jonathan M Davis wrote: 2. Or make it a range (see http://dlang.org/statement.html#foreach_with_ranges and http://ddili.org/ders/d.en/ranges.html ), which would probably be a bad idea, since containers really shouldn't be ranges. Why is that a bad idea? -- /Jacob

Re: How to define an interator to provide array like behaviour in a class?

2012-10-17 Thread Jonathan M Davis
On Wednesday, October 17, 2012 08:14:45 Jacob Carlborg wrote: On 2012-10-17 00:23, Jonathan M Davis wrote: 2. Or make it a range (see http://dlang.org/statement.html#foreach_with_ranges and http://ddili.org/ders/d.en/ranges.html ), which would probably be a bad idea, since containers

Re: optlink and weak symbols

2012-10-17 Thread Jacob Carlborg
On 2012-10-17 07:07, Ellery Newcomer wrote: I am interfacing with some C code [python.dll], which has some structs declared like so: PyTypeObject PyType_Type; I wish to be able to link to PyType_Type like so: extern(C) __gshared PyTypeObject PyType_Type; in linux, I can do exactly that, but

Re: How to define an interator to provide array like behaviour in a class?

2012-10-17 Thread Jacob Carlborg
On 2012-10-17 08:17, Jonathan M Davis wrote: For starters, iterating over the container would empty it. Right, but that is really weird, in my opinion. -- /Jacob Carlborg

Re: Stack trace output on windows

2012-10-17 Thread Regan Heath
On Tue, 16 Oct 2012 17:52:38 +0100, Benjamin Thaut c...@benjamin-thaut.de wrote: Am 16.10.2012 18:38, schrieb Regan Heath: I have some C/C++ code which handles windows SEH exceptions and can output (in debug mode) a stack trace, for example: But, it doesn't output symbol names for the

Re: Operator overloading through UFCS doesn't work

2012-10-17 Thread Timon Gehr
On 10/16/2012 05:57 PM, Maxim Fomin wrote: ... At NG discussion it may look nice to define some type and then add operator overloading methods Operator overloading is not magic, so your statement can be shortened to ... and then add methods Which is still not correct, because that is not

Re: Operator overloading through UFCS doesn't work

2012-10-17 Thread Timon Gehr
On 10/14/2012 09:14 AM, Maxim Fomin wrote: On Sunday, 14 October 2012 at 07:01:30 UTC, Tommi wrote: Actually, it seems that alias this has precedence over UFCS. So, a free function opUnary wouldn't ever suit better than an actual method opUnary of the thing referred to by that alias this.

Re: Operator overloading through UFCS doesn't work

2012-10-17 Thread Maxim Fomin
On Wednesday, 17 October 2012 at 10:24:57 UTC, Artur Skawina wrote: Operator overloading can be abused - that's an obvious and well known fact. But that same feature can also be very useful, if used right. Worrying about UFCS problems in the context of op-overloading needlessly complicates the

Re: Stack trace output on windows

2012-10-17 Thread Benjamin Thaut
I didn't go through the trouble and find out which version of dbghelp.dll exactly supports cv debugging symbols, but I know it depends on that. So I can not help you there. The linker line looks fine, looks the same for me but works (also with dmd 2.060) Did you modify your sc.ini file?

Re: Operator overloading through UFCS doesn't work

2012-10-17 Thread Timon Gehr
On 10/14/2012 09:01 AM, Maxim Fomin wrote: On Saturday, 13 October 2012 at 19:50:02 UTC, Timon Gehr wrote: On 10/13/2012 06:02 PM, Maxim Fomin wrote: ... Different groups of people have different mind and same things produce different sense on them. From my point of view operator overloading

Re: Operator overloading through UFCS doesn't work

2012-10-17 Thread Maxim Fomin
On Wednesday, 17 October 2012 at 11:00:05 UTC, Timon Gehr wrote: On 10/16/2012 05:57 PM, Maxim Fomin wrote: ... At NG discussion it may look nice to define some type and then add operator overloading methods Operator overloading is not magic, so your statement can be shortened to ...

Re: How to define an interator to provide array like behaviour in a class?

2012-10-17 Thread Jacob Carlborg
On 2012-10-17 17:45, Jonathan M Davis wrote: Well, what would you expect? Ranges are consumed when you iterate over them. So, if an container is a range, it will be consumed when you iterate over it. That's the way that it _has_ to work given how ranges work, and that's why you overload opSlice

Re: How to define an interator to provide array like behaviour in a class?

2012-10-17 Thread H. S. Teoh
On Wed, Oct 17, 2012 at 06:58:52PM +0200, Jacob Carlborg wrote: On 2012-10-17 17:45, Jonathan M Davis wrote: Well, what would you expect? Ranges are consumed when you iterate over them. So, if an container is a range, it will be consumed when you iterate over it. That's the way that it

Re: How to define an interator to provide array like behaviour in a class?

2012-10-17 Thread Ali Çehreli
On 10/17/2012 09:58 AM, Jacob Carlborg wrote: On 2012-10-17 17:45, Jonathan M Davis wrote: Well, what would you expect? Ranges are consumed when you iterate over them. So, if an container is a range, it will be consumed when you iterate over it. That's the way that it _has_ to work given

Re: Code review: JSON unmarshaller

2012-10-17 Thread Tyler Jameson Little
I could make my marshaller/unmarshaller only update objects in place. I think this is more useful and would remove the overlap between orange and the JSON library. We could then write a JSON archiver for orange and include it in std.json as well. The call to unmarshal would look like: bool

Re: How to define an interator to provide array like behaviour in a class?

2012-10-17 Thread Jonathan M Davis
On Wednesday, October 17, 2012 10:08:15 H. S. Teoh wrote: On Wed, Oct 17, 2012 at 06:58:52PM +0200, Jacob Carlborg wrote: On 2012-10-17 17:45, Jonathan M Davis wrote: Well, what would you expect? Ranges are consumed when you iterate over them. So, if an container is a range, it will be

Re: Code review: JSON unmarshaller

2012-10-17 Thread Tyler Jameson Little
You have mentioned needing an allMembers that excluded functions in one of your other posts. The following thread was exactly about that. I can never remember the solution, but I found it again: :)

Re: Sorting algorithms

2012-10-17 Thread Philippe Sigaud
On Mon, Oct 15, 2012 at 5:52 PM, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: I wanted to investigate small sorts using sorting networks for ages, but never got around to it. That's important for quicksort because it produces many small arrays that need sorting. Could you also

Returning dynamic array from the function

2012-10-17 Thread m0rph
I tryed to learn how arrays works and found another strange thing: import std.stdio; int[] create() { int[5] a1 = [ 10, 20, 30, 40, 50 ]; int[] b1 = a1; writeln(b1: , b1); return b1; } void main() { int[] a2 = create(); writeln(a2: , a2); }

Re: Returning dynamic array from the function

2012-10-17 Thread Simen Kjaeraas
On 2012-10-17, 21:17, m0rph wrote: I tryed to learn how arrays works and found another strange thing: import std.stdio; int[] create() { int[5] a1 = [ 10, 20, 30, 40, 50 ]; int[] b1 = a1; writeln(b1: , b1); return b1; } void main() { int[] a2 =

Re: Returning dynamic array from the function

2012-10-17 Thread sclytrack
On Wednesday, 17 October 2012 at 19:22:05 UTC, Simen Kjaeraas wrote: On 2012-10-17, 21:17, m0rph wrote: I tryed to learn how arrays works and found another strange thing: import std.stdio; int[] create() { int[5] a1 = [ 10, 20, 30, 40, 50 ]; int[] b1 = a1;

Re: Code review: JSON unmarshaller

2012-10-17 Thread Tyler Jameson Little
Here's the updated code. It's got a marshaller and unmarshaller: https://gist.github.com/3894337 It's about 650 lines. If you have time, I'd be very interested in getting some feedback (or from anyone else who sees this post of course). The main problem I'm having right now is that

Re: Returning dynamic array from the function

2012-10-17 Thread m0rph
b1 points to the exact same data as does a1. This data is stack- allocated, and thus a2 points to an overwritten stack frame. Thanks for explanation, I thought contetns of a1 are copied to the heap when assignment operator executed.

Re: Returning dynamic array from the function

2012-10-17 Thread bearophile
sclytrack: It doesn't give an error when marking the function with safe. @safe int[] create() { } I think marking it @safe is not relevant. In theory a good type system should give an error message on similar code. I don't know if D is supposed to spot similar error situations. Bye,

Re: Code review: JSON unmarshaller

2012-10-17 Thread Kagamin
On Tuesday, 16 October 2012 at 06:37:55 UTC, Jacob Carlborg wrote: The goal of Orange was to be able serialize basically everything found in D. Can it serialize Variant?

Re: Returning dynamic array from the function

2012-10-17 Thread Jonathan M Davis
On Wednesday, October 17, 2012 21:46:50 bearophile wrote: sclytrack: It doesn't give an error when marking the function with safe. @safe int[] create() { } I think marking it @safe is not relevant. In theory a good type system should give an error message on similar code. I don't

Re: Returning dynamic array from the function

2012-10-17 Thread sclytrack
On Wednesday, 17 October 2012 at 19:46:51 UTC, bearophile wrote: sclytrack: It doesn't give an error when marking the function with safe. @safe int[] create() { } I think marking it @safe is not relevant. In theory a good type system should give an error message on similar code. I don't

Re: Operator overloading through UFCS doesn't work

2012-10-17 Thread Artur Skawina
On 10/17/12 12:46, Timon Gehr wrote: On 10/15/2012 01:00 PM, Artur Skawina wrote: ... An overloaded operator is just another normal method; you get the same type of problems when dealing with normal methods - eg in types having an alias this - an UFCS method must take precedence over

Re: Returning dynamic array from the function

2012-10-17 Thread bearophile
Jonathan M Davis: there's no way for the compiler to always catch it for you. I think there are type systems able to always catch this kind of bug (conservative region analysis, it means that if it can't demonstrate the memory doesn't escape, it prudently refuses the code). D doesn't have

Re: Returning dynamic array from the function

2012-10-17 Thread Era Scarecrow
The only way that @safe could really be applicable would be if it became @system to take the address of a local variable or to slice a static array. And perhaps it should be, but that and catching the most obvious cases are all that the compiler could do to catch this for you. Hmmm, you

Re: Returning dynamic array from the function

2012-10-17 Thread Jonathan M Davis
On Wednesday, October 17, 2012 13:07:13 Jonathan M Davis wrote: The only way that @safe could really be applicable would be if it became @system to take the address of a local variable or to slice a static array. And perhaps it should be, but that and catching the most obvious cases are all

Re: How to define an interator to provide array like behaviour in a class?

2012-10-17 Thread Gary Willoughby
1. Define opApply (see section labeled Foreach over Structs and Classes with opApply after here: http://dlang.org/statement.html#foreach_with_ranges) 2. Or make it a range (see http://dlang.org/statement.html#foreach_with_ranges and http://ddili.org/ders/d.en/ranges.html ), which would

Re: Returning dynamic array from the function

2012-10-17 Thread Timon Gehr
On 10/17/2012 10:15 PM, sclytrack wrote: On Wednesday, 17 October 2012 at 19:46:51 UTC, bearophile wrote: sclytrack: It doesn't give an error when marking the function with safe. @safe int[] create() { } I think marking it @safe is not relevant. In theory a good type system should give an

Re: Code review: JSON unmarshaller

2012-10-17 Thread Adam D. Ruppe
On Wednesday, 17 October 2012 at 19:44:47 UTC, Tyler Jameson Little wrote: The main problem I'm having right now is that classes/structs have to be static. That seems weird, I've done something similar with non-static structs before. Maybe it will help if you use __traits(getMember, obj,

Re: Sorting algorithms

2012-10-17 Thread Andrei Alexandrescu
On 10/17/12 3:07 PM, Philippe Sigaud wrote: On Mon, Oct 15, 2012 at 5:52 PM, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: I wanted to investigate small sorts using sorting networks for ages, but never got around to it. That's important for quicksort because it produces many small

std.range.chunks for char[]

2012-10-17 Thread cal
Is there an equivalent to std.range.chunks that will work on a char array? As in, it will return a range iterating over chunks of code points?

Re: std.range.chunks for char[]

2012-10-17 Thread Jonathan M Davis
On Thursday, October 18, 2012 01:19:02 cal wrote: Is there an equivalent to std.range.chunks that will work on a char array? As in, it will return a range iterating over chunks of code points? Not that I'm aware of (though there _may_ be a function that you could do it with that I'm not

independent or parallel process

2012-10-17 Thread drpepper
I want the function below to run independently -- like a unix background process, without delaying subsequent code in main. I tried the following using std.parallelism: void main() { function_a(int a, int b) { ... } auto new_task = task!function_a(11, 12);

Re: optlink and weak symbols

2012-10-17 Thread Ellery Newcomer
On 10/16/2012 11:16 PM, Jacob Carlborg wrote: You need to declare the variable as extern if it's defined in the C code: extern(C) extern __gshared PyTypeObject PyType_Type; http://dlang.org/interfaceToC.html#C%20Globals nice tip, but adding extern doesn't change link behavior at all.