std.concurrency msg passing

2012-10-18 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

Re: Code review: JSON unmarshaller

2012-10-18 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: Code review: JSON unmarshaller

2012-10-18 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

Re: Code review: JSON unmarshaller

2012-10-18 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)

Re: Code review: JSON unmarshaller

2012-10-18 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

Re: optlink and weak symbols

2012-10-18 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

Friends?

2012-10-18 Thread Jeremy DeHaan
Hey guys! I think I understand the reasoning behind the idea that classes in the same module are automatically friends, but why isn't there any way to have this sort of relationship between classes outside of a module? I feel like there are times when it doesn't always make sense to have

Re: Friends?

2012-10-18 Thread Jonathan M Davis
On Thursday, October 18, 2012 10:09:46 Jeremy DeHaan wrote: Is there any kind of work around for this functionality? The package access modifier. - Jonathan M Davis

Re: Code review: JSON unmarshaller

2012-10-18 Thread Jacob Carlborg
On 2012-10-17 22:03, Kagamin wrote: Can it serialize Variant? No, but I'm working on it. Actually, it can serialize it, but not deserialize it. -- /Jacob Carlborg

Re: Friends?

2012-10-18 Thread Jeremy DeHaan
On Thursday, 18 October 2012 at 08:12:42 UTC, Jonathan M Davis wrote: On Thursday, October 18, 2012 10:09:46 Jeremy DeHaan wrote: Is there any kind of work around for this functionality? The package access modifier. - Jonathan M Davis You, good sir, are now my new best friend.

undefined identifier

2012-10-18 Thread Oleg
Hello I have struct in one module (vector.d) struct vec(string S, T=double) if( is(T:real) onlyASCII(S) ) { private T[S.length] _data; alias vec!(S,T) ttype; alias _data this; mixin _workaround4424; auto opAssign(E)( E[] b ) if( is( E : T ) ) { if( b.length

Re: optlink and weak symbols

2012-10-18 Thread Regan Heath
On Thu, 18 Oct 2012 07:41:16 +0100, Jacob Carlborg d...@me.com wrote: 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

Re: private module members

2012-10-18 Thread Oleg Kuporosov
Is it in Bugzilla? Bye, bearophile Thanks. I had assumed my interpretation was incorrect and was just looking for an explanation. Honestly, until just now, I have not explored bugzilla. There is bug 1141 which looks like what I'm asking about and references a newer one 2830 which looks

Re: undefined identifier

2012-10-18 Thread Oleg
solved. its associated with access private for _data field. if I use alias compiler must replace call a (for my type) to a._data if it needs...

Re: Extending library functions

2012-10-18 Thread simendsjo
On Thursday, 18 October 2012 at 11:31:47 UTC, tn wrote: Hi. I want to extend math library functions to work with my own type. However, the definition for my own type seems to prevent automated access to the original function. How can I fix this unexpected behavior? Simplified example:

Re: Code review: JSON unmarshaller

2012-10-18 Thread Dan
On Monday, 15 October 2012 at 20:35:34 UTC, Tyler Jameson Little wrote: I'm basically trying to reproduce other JSON marshallers, like Go's, but using compile-time reflection. Go uses runtime reflection, which D notably does not support. I like the idea of compile-time reflection better

Re: optlink and weak symbols

2012-10-18 Thread Ellery Newcomer
On 10/17/2012 11:41 PM, Jacob Carlborg wrote: 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.

Re: Extending library functions

2012-10-18 Thread tn
On Thursday, 18 October 2012 at 11:43:40 UTC, simendsjo wrote: On Thursday, 18 October 2012 at 11:31:47 UTC, tn wrote: Hi. I want to extend math library functions to work with my own type. However, the definition for my own type seems to prevent automated access to the original function. How

Re: Extending library functions

2012-10-18 Thread simendsjo
On Thursday, 18 October 2012 at 12:10:17 UTC, tn wrote: On Thursday, 18 October 2012 at 11:43:40 UTC, simendsjo wrote: On Thursday, 18 October 2012 at 11:31:47 UTC, tn wrote: (...) You need to manually add std.math.exp2 to the overload set so importing external methods doesn't hijack your

Re: Extending library functions

2012-10-18 Thread tn
On Thursday, 18 October 2012 at 13:35:55 UTC, simendsjo wrote: On Thursday, 18 October 2012 at 12:10:17 UTC, tn wrote: On Thursday, 18 October 2012 at 11:43:40 UTC, simendsjo wrote: On Thursday, 18 October 2012 at 11:31:47 UTC, tn wrote: (...) You need to manually add std.math.exp2 to the

Re: Extending library functions

2012-10-18 Thread bearophile
simendsjo: I don't think you can overload template methods with non-template methods: But maybe this will change. Bye, bearophile

opCast using in template struct

2012-10-18 Thread Oleg
Hello. How to cast template struct to itself? struct vec(string S,T=double) { T[S.length] data; auto opCast(string K,E)() if( S.length == K.length is( T : E ) ) { vec!(K,E) ret; foreach( i, ref m; ret.data ) m = data[i];

Re: opCast using in template struct

2012-10-18 Thread Oleg
Sorry. My problem more complex and my simplification is not correct. I want use mixin for math operations. mixin template vectOp( string DataName, int DataLen, T, vecType ) { mixin( alias ~ DataName ~ this; ); auto opBinary(string op,E)( E[DataLen] b ) auto

Re: std.concurrency msg passing

2012-10-18 Thread cal
On Thursday, 18 October 2012 at 06:30:08 UTC, Joshua Niehus wrote: 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 =

Re: std.concurrency msg passing

2012-10-18 Thread Ali Çehreli
On 10/17/2012 11:29 PM, Joshua Niehus wrote: 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) {

Re: independent or parallel process

2012-10-18 Thread Ali Çehreli
On 10/17/2012 07:46 PM, drpepper wrote: 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,

Re: Friends?

2012-10-18 Thread Philippe Sigaud
On Thu, Oct 18, 2012 at 11:12 AM, Jeremy DeHaan dehaan.jerem...@gmail.com wrote: On Thursday, 18 October 2012 at 08:12:42 UTC, Jonathan M Davis wrote: On Thursday, October 18, 2012 10:09:46 Jeremy DeHaan wrote: Is there any kind of work around for this functionality? The package access

Re: opCast using in template struct

2012-10-18 Thread Simen Kjaeraas
On 2012-10-18, 17:45, Oleg wrote: Sorry. My problem more complex and my simplification is not correct. I want use mixin for math operations. mixin template vectOp( string DataName, int DataLen, T, vecType ) { mixin( alias ~ DataName ~ this; ); auto opBinary(string op,E)(

Re: std.concurrency msg passing

2012-10-18 Thread Sean Kelly
On Oct 17, 2012, at 11:29 PM, Joshua Niehus jm.nie...@gmail.com wrote: 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 =

Re: std.concurrency msg passing

2012-10-18 Thread cal
On Thursday, 18 October 2012 at 18:31:09 UTC, Sean Kelly wrote: On Oct 17, 2012, at 11:29 PM, Joshua Niehus void foo(Tid tid) { send(tid, true); } /* snip */ spawn() shouldn't allow you to spawn a delegate. Last I checked (which was admittedly a while ago), there were some compiler

Re: optlink and weak symbols

2012-10-18 Thread Jacob Carlborg
On 2012-10-18 13:55, Ellery Newcomer wrote: I am using python27_digitalmars.lib, which is generated from libs\python27.lib with coffimplib, and it is linking my executables with python.dll. Ok. Do you know how the corresponding C code would look like? Maybe you need to use the export

Re: Extending library functions

2012-10-18 Thread Jacob Carlborg
On 2012-10-18 15:35, simendsjo wrote: I don't think you can overload template methods with non-template methods You cannot. The usual workaround for this is to make the non-template method a dummy template: void foo () (int a) {} // Note the extra pair of empty parentheses But this won't

Re: Friends?

2012-10-18 Thread Jacob Carlborg
On 2012-10-18 19:57, Philippe Sigaud wrote: Does it work? I thought it was not implemented. Define work. They're not virtual, which this would imply: All non-static non-private non-template member functions are virtual. http://dlang.org/function.html#virtual-functions -- /Jacob Carlborg

Re: std.concurrency msg passing

2012-10-18 Thread Sean Kelly
On Oct 18, 2012, at 11:35 AM, cal callumena...@gmail.com wrote: On Thursday, 18 October 2012 at 18:31:09 UTC, Sean Kelly wrote: On Oct 17, 2012, at 11:29 PM, Joshua Niehus void foo(Tid tid) { send(tid, true); } /* snip */ spawn() shouldn't allow you to spawn a delegate. Last I checked

Re: std.concurrency msg passing

2012-10-18 Thread Joshua Niehus
On Thursday, 18 October 2012 at 17:33:04 UTC, cal wrote: I can't see the bug? The receiver accepts a bool as an int, same way a normal function does. The timeout is long enough that foo gets a chance to send. If you want to stop the int receiver getting a bool, you could add another receiver

Re: Extending library functions

2012-10-18 Thread Jonathan M Davis
On Thursday, October 18, 2012 16:22:17 bearophile wrote: simendsjo: I don't think you can overload template methods with non-template methods: But maybe this will change. It's bug (I forget the exact bug number). TDPL says that you can do it, and as I understand it, it's simply a

Re: Friends?

2012-10-18 Thread Jonathan M Davis
On Thursday, October 18, 2012 20:42:08 Jacob Carlborg wrote: On 2012-10-18 19:57, Philippe Sigaud wrote: Does it work? I thought it was not implemented. Define work. They're not virtual, which this would imply: All non-static non-private non-template member functions are virtual.

Re: Friends?

2012-10-18 Thread Jonathan M Davis
Does it work? I thought it was not implemented. Hmm. I don't know what it's current state is. There _is_ a long-standing bug on it in bugzilla ( http://d.puremagic.com/issues/show_bug.cgi?id=143 ) which is still open. I had forgotten about it. But the bug is that package doesn't restrict when

Re: opCast using in template struct

2012-10-18 Thread Era Scarecrow
On Thursday, 18 October 2012 at 18:12:49 UTC, Simen Kjaeraas wrote: I see you have opOpBinary there - should those be opOpAssign? Probably. It's an easy mistake to make. Maybe the compiler should issue a warning when opAssign attempts and fails and opOpBinary is defined.

Re: opCast using in template struct

2012-10-18 Thread bearophile
Era Scarecrow: It's an easy mistake to make. Maybe the compiler should issue a warning when opAssign attempts and fails and opOpBinary is defined. If you have strong feelings about this, then add a Bugzilla entry. There are other cases. Generally the D compiler should add some warnings

Re: opCast using in template struct

2012-10-18 Thread Timon Gehr
On 10/18/2012 11:45 PM, bearophile wrote: Era Scarecrow: It's an easy mistake to make. Maybe the compiler should issue a warning when opAssign attempts and fails and opOpBinary is defined. This would have to be implemented very carefully. There are enough hard to reproduce symbol

Re: opCast using in template struct

2012-10-18 Thread Era Scarecrow
On Thursday, 18 October 2012 at 22:07:55 UTC, Timon Gehr wrote: On 10/18/2012 11:45 PM, bearophile wrote: There are other cases. Generally the D compiler should add some warnings that help against operator overloading mistakes. I don't think that operator overloading gives rise to distinct

Re: opCast using in template struct

2012-10-18 Thread bearophile
Era Scarecrow: Maybe.. A general warning when something starts with 'op(Op)?[A-Z]' but doesn't actually qualify as any of the override-able operators? That seems sensible... Regarding operator overloading there are several situations worth warning the programmer of. The D compilers should

Re: opCast using in template struct

2012-10-18 Thread Timon Gehr
On 10/19/2012 01:05 AM, Era Scarecrow wrote: On Thursday, 18 October 2012 at 22:07:55 UTC, Timon Gehr wrote: On 10/18/2012 11:45 PM, bearophile wrote: There are other cases. Generally the D compiler should add some warnings that help against operator overloading mistakes. I don't think that

Re: opCast using in template struct

2012-10-18 Thread Timon Gehr
On 10/19/2012 01:23 AM, bearophile wrote: Era Scarecrow: Maybe.. A general warning when something starts with 'op(Op)?[A-Z]' but doesn't actually qualify as any of the override-able operators? That seems sensible... Regarding operator overloading there are several situations worth warning

Re: opCast using in template struct

2012-10-18 Thread bearophile
Timon Gehr: What situations? This thread has already shown two possible cases worth discussing about. This report shows two more cases: http://d.puremagic.com/issues/show_bug.cgi?id=8844 Two more cases: Foo opBinary(string op=/\)(Foo f) {} Foo opBinary(string op)(Foo f) if (op == @) {}

Re: opCast using in template struct

2012-10-18 Thread Timon Gehr
On 10/19/2012 02:12 AM, bearophile wrote: Timon Gehr: What situations? This thread has already shown two possible cases worth discussing about. This report shows two more cases: http://d.puremagic.com/issues/show_bug.cgi?id=8844 How is that bug-prone? Are there keyboards where : and =

Re: optlink and weak symbols

2012-10-18 Thread Ellery Newcomer
On 10/18/2012 11:36 AM, Jacob Carlborg wrote: On 2012-10-18 13:55, Ellery Newcomer wrote: I am using python27_digitalmars.lib, which is generated from libs\python27.lib with coffimplib, and it is linking my executables with python.dll. Ok. Do you know how the corresponding C code would look

Re: independent or parallel process

2012-10-18 Thread drpepper
Thank you Ali, Indeed, I originally had the function outside of main. I have found another strange result with std.concurrency: spawn(function, array[0].length, array.length); // generates compiling error: cannot deduce template function from arg types //Yet, int var_one = array[0].length;

Re: independent or parallel process

2012-10-18 Thread Ali Çehreli
On 10/18/2012 06:34 PM, drpepper wrote: Thank you Ali, Indeed, I originally had the function outside of main. I have found another strange result with std.concurrency: spawn(function, array[0].length, array.length); // generates compiling error: cannot deduce template function from arg

Re: Friends?

2012-10-18 Thread Jeremy DeHaan
On Thursday, 18 October 2012 at 20:44:42 UTC, Jonathan M Davis wrote: Does it work? I thought it was not implemented. Hmm. I don't know what it's current state is. There _is_ a long-standing bug on it in bugzilla ( http://d.puremagic.com/issues/show_bug.cgi?id=143 ) which is still open. I

Re: Problem with UFCS

2012-10-18 Thread Michael
Thank you guys. I can't believe that haven't thought of that. I still feel that this is rather odd though. I would expect to be able to use UFCS in the scope that imports those libraries. Though I can definitely see how that might lead to obscure bugs. On Tuesday, 16 October 2012 at 17:07:36

Implicit Conversions in Struct Construction

2012-10-18 Thread Michael
Hello, I have been playing around with templated range. I am not quite sure why the following code does not work: template isIntLike(T) { enum isIntLike = is(typeof({ T t = 0; t = t+t; // More if needed })); } auto fib(T =

Re: Implicit Conversions in Struct Construction

2012-10-18 Thread Jonathan M Davis
On Friday, October 19, 2012 05:44:10 Michael wrote: Hello, I have been playing around with templated range. I am not quite sure why the following code does not work: template isIntLike(T) { enum isIntLike = is(typeof({ T t = 0; t = t+t;

Re: Implicit Conversions in Struct Construction

2012-10-18 Thread Jonathan M Davis
On Thursday, October 18, 2012 20:55:12 Ali Çehreli wrote: Explicit conversion works: return Fib(T(0), T(1)); Except that that won't work for int or other built-in types, because they lack constructors. What you need is std.conv.to. - Jonathan M Davis