Re: optlink and weak symbols

2012-10-17 Thread Jacob Carlborg
On 2012-10-18 05:12, Ellery Newcomer wrote: nice tip, but adding extern doesn't change link behavior at all. Hmm, are you linking with the DLL (the import library) ? In not, you need to use dlopen, or what the corresponding Windows function is. -- /Jacob Carlborg

Re: Code review: JSON unmarshaller

2012-10-17 Thread Jacob Carlborg
On 2012-10-17 21:44, Tyler Jameson Little wrote: 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). I'll tr

Re: Code review: JSON unmarshaller

2012-10-17 Thread Jacob Carlborg
On 2012-10-17 21:44, Tyler Jameson Little wrote: 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

Re: Code review: JSON unmarshaller

2012-10-17 Thread Jacob Carlborg
On 2012-10-17 20:36, Tyler Jameson Little wrote: The mentioned solution doesn't account for shared fields from a super class: class A { int a; } class S { int b; } foreach (i, type; typeof(S.tupleof)) { enum name = S.tupleof[i].stringof[4..$]; writef("(%s) %s\n

std.concurrency msg passing

2012-10-17 Thread Joshua Niehus
Is the following snippet a bug? --- import core.thread; import std.stdio, std.concurrency; void foo(Tid tid) { send(tid, true); } void main() { auto fooTid = spawn(&foo, thisTid); auto receiveInt = receiveTimeout(dur!"seconds"(10), (int isInt) { writeln("I should not be he

Re: Code review: JSON unmarshaller

2012-10-17 Thread Jacob Carlborg
On 2012-10-17 19:39, Tyler Jameson Little wrote: 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.

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.

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); new_task.executeInNewT

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 thi

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 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. Cou

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: 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, nam

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 e

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 proba

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: 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 coul

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: 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 ta

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 kn

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 simila

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 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, bearo

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 classes/s

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; writeln("b1

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 = create

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); } R

Re: Sorting algorithms

2012-10-17 Thread Philippe Sigaud
On Mon, Oct 15, 2012 at 5:52 PM, Andrei Alexandrescu 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 test for very small sizes (

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: :) http://www.digitalmars.com/d/archives/digitalmars/D/learn/Getting_only_the_data_members_of_a_ty

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

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 un

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 w

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

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: OPTLINK bug (Re: Stack trace output on windows)

2012-10-17 Thread Regan Heath
On Wed, 17 Oct 2012 13:02:45 +0100, Benjamin Thaut wrote: Am 17.10.2012 13:56, schrieb Regan Heath: On Wed, 17 Oct 2012 12:43:27 +0100, Regan Heath wrote: On Wed, 17 Oct 2012 12:17:14 +0100, Benjamin Thaut wrote: I didn't go through the trouble and find out which version of dbghelp.dll

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:58:33 Jacob Carlborg wrote: > 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. Well, what would you expect? Ranges are consumed when you iterate over th

Re: Operator overloading through UFCS doesn't work

2012-10-17 Thread Timon Gehr
On 10/17/2012 01:51 PM, Maxim Fomin wrote: On Wednesday, 17 October 2012 at 11:11:26 UTC, Timon Gehr wrote: 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 opUna

Re: Operator overloading through UFCS doesn't work

2012-10-17 Thread Timon Gehr
On 10/17/2012 01:32 PM, Maxim Fomin wrote: 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 you

Re: OPTLINK bug (Re: Stack trace output on windows)

2012-10-17 Thread Benjamin Thaut
Am 17.10.2012 13:56, schrieb Regan Heath: On Wed, 17 Oct 2012 12:43:27 +0100, Regan Heath wrote: On Wed, 17 Oct 2012 12:17:14 +0100, Benjamin Thaut wrote: 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 o

OPTLINK bug (Re: Stack trace output on windows)

2012-10-17 Thread Regan Heath
On Wed, 17 Oct 2012 12:43:27 +0100, Regan Heath wrote: On Wed, 17 Oct 2012 12:17:14 +0100, Benjamin Thaut wrote: 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.

Re: Operator overloading through UFCS doesn't work

2012-10-17 Thread Maxim Fomin
On Wednesday, 17 October 2012 at 11:11:26 UTC, Timon Gehr wrote: 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

Re: Stack trace output on windows

2012-10-17 Thread Regan Heath
On Wed, 17 Oct 2012 12:17:14 +0100, Benjamin Thaut wrote: 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 wor

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 ... and

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 me

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? Kin

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 i

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. http

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 wha

Re: Stack trace output on windows

2012-10-17 Thread Regan Heath
On Tue, 16 Oct 2012 17:52:38 +0100, Benjamin Thaut 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 D functions. Does

Re: Operator overloading through UFCS doesn't work

2012-10-17 Thread Timon Gehr
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 one reachable via the alias - just lik

Re: Operator overloading through UFCS doesn't work

2012-10-17 Thread Artur Skawina
On 10/16/12 17:57, Maxim Fomin wrote: > This doesn't scale well. Certanly, nobody would intentionally create > problems. But if you import code of other people, whom you cannot control, > override problems occurs. > > At NG discussion it may look nice to define some type and then add operator >

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

2012-10-17 Thread Era Scarecrow
On Wednesday, 17 October 2012 at 06:07:34 UTC, ixid wrote: 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. True... But if you're planning on g

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