Re: Templates and stringof...

2012-08-04 Thread Philippe Sigaud
Le 4 août 2012 00:50, David Nadlinger s...@klickverbot.at a écrit : On Friday, 3 August 2012 at 22:23:23 UTC, Era Scarecrow wrote: Seems like an ugly hack though (to get this done). Why not have another method of fullpathStringof or something similar? Then again if this is one of the few

Re: Templates and stringof...

2012-08-04 Thread Jonathan M Davis
On Saturday, August 04, 2012 09:57:36 Philippe Sigaud wrote: For std.reflection that Andrei proposed 2 weeks ago, I feel the internal code will contain many __traits() calls. Nothing to be done about it. __traits is *the* way compile-time introspection is done in D. That and std.traits.

Re: Templates and stringof...

2012-08-04 Thread Philippe Sigaud
Era Scarecrow rtcv...@yahoo.com Then doesn't it seem like we're missing a potentially important piece of the puzzle for mixins and templates? very likely my modified template will include you including the same variable twice, but if someone gets lazy then it may not work.

Re: Templates and stringof...

2012-08-04 Thread Era Scarecrow
On Saturday, 4 August 2012 at 07:57:46 UTC, Philippe Sigaud wrote: FWIW, I agree with David that using .stringof is a last resort and can lead to nasty bugs. .stringof has a sometime incoherent behavior (I remember it showing the entire code inside a delegate literal) But then, the code

Re: Templates and stringof...

2012-08-04 Thread David Nadlinger
On Saturday, 4 August 2012 at 08:06:31 UTC, Jonathan M Davis wrote: On Saturday, August 04, 2012 09:57:36 Philippe Sigaud wrote: For std.reflection that Andrei proposed 2 weeks ago, I feel the internal code will contain many __traits() calls. Nothing to be done about it. __traits is *the* way

Re: Templates and stringof...

2012-08-04 Thread David Nadlinger
On Saturday, 4 August 2012 at 07:57:46 UTC, Philippe Sigaud wrote: It uses __traits(parent, ) and __traits(qualifier, ), which are much more 'modern' and well-behaved. An example of what I mean: Try this with your CurryTemplate from dranges: --- import dranges.templates; template Foo(A,

Re: How to use read_bool?

2012-08-04 Thread simendsjo
On Sat, 04 Aug 2012 03:01:31 +0200, Zeh zec...@yahoo.com.br wrote: Thanks for the help, but i tryed both solutions posted and still not working. :/ I get erros to compile the code posted by simendsjo. I try modify at my own, but without success. The code suggest by Timon Gehr compiles, but

Re: Templates and stringof...

2012-08-04 Thread Philippe Sigaud
On Sat, Aug 4, 2012 at 10:25 AM, David Nadlinger s...@klickverbot.at wrote: An example of what I mean: Try this with your CurryTemplate from dranges: --- import dranges.templates; template Foo(A, B) { pragma(msg, A.stringof, , B.stringof); } alias CurryTemplate!Foo FooCurried;

Re: Templates and stringof...

2012-08-04 Thread David Nadlinger
On Saturday, 4 August 2012 at 11:29:36 UTC, Philippe Sigaud wrote: Oh, I completely forgot this. Nice code, if I may say so myself :) Huh? It's broken, precisely because of the use of __traits(identifier, …) in combination with string mixins. The example doesn't compile. David

Re: Templates and stringof...

2012-08-04 Thread Philippe Sigaud
On Sat, Aug 4, 2012 at 1:35 PM, David Nadlinger s...@klickverbot.at wrote: On Saturday, 4 August 2012 at 11:29:36 UTC, Philippe Sigaud wrote: Oh, I completely forgot this. Nice code, if I may say so myself :) Huh? It's broken, precisely because of the use of __traits(identifier, …) in

Why does foreach with __traits ignore ForeachTypeList's type ?

2012-08-04 Thread Eyyub
Hi, As I said on #d, foreach with __traits seems to ignore ForeachTypeList's type. Look at this ! :p http://dpaste.dzfl.pl/0885e1de Wtf ? Thanks

Re: Variadic Template: cast problem

2012-08-04 Thread Dmitry Olshansky
On 04-Aug-12 17:57, Namespace wrote: This code http://dpaste.dzfl.pl/6caed813 does only compile if i comment out the Clone method. Why? o.O Because it calls constructor and fails? I've done substitution for you: this(const vec!(float,2) values) { foreach (index, val; values) {

Re: Why does foreach with __traits ignore ForeachTypeList's type ?

2012-08-04 Thread Eyyub
It looks like the problem is TypeTuple : http://dpaste.dzfl.pl/de2264dd

Re: Variadic Template: cast problem

2012-08-04 Thread Namespace
On Saturday, 4 August 2012 at 14:05:32 UTC, Dmitry Olshansky wrote: On 04-Aug-12 17:57, Namespace wrote: This code http://dpaste.dzfl.pl/6caed813 does only compile if i comment out the Clone method. Why? o.O Because it calls constructor and fails? I've done substitution for you: this(const

Re: Why does foreach with __traits ignore ForeachTypeList's type ?

2012-08-04 Thread bearophile
Eyyub: It looks like the problem is TypeTuple : http://dpaste.dzfl.pl/de2264dd Fixed in DMD 2.060? http://d.puremagic.com/issues/show_bug.cgi?id=5435 Bye, bearophile

Re: Why does foreach with __traits ignore ForeachTypeList's type ?

2012-08-04 Thread Eyyub
On Saturday, 4 August 2012 at 14:27:44 UTC, bearophile wrote: Eyyub: It looks like the problem is TypeTuple : http://dpaste.dzfl.pl/de2264dd Fixed in DMD 2.060? http://d.puremagic.com/issues/show_bug.cgi?id=5435 Bye, bearophile Oh, indeed. Sorry I did not look at the changelog before

Re: Variadic Template: cast problem

2012-08-04 Thread Dmitry Olshansky
n 04-Aug-12 18:16, Namespace wrote: On Saturday, 4 August 2012 at 14:05:32 UTC, Dmitry Olshansky wrote: On 04-Aug-12 17:57, Namespace wrote: This code http://dpaste.dzfl.pl/6caed813 does only compile if i comment out the Clone method. Why? o.O Because it calls constructor and fails? I've

Re: Variadic Template: cast problem

2012-08-04 Thread Namespace
http://dpaste.dzfl.pl/ff58ffc5 I'm even more confused. o.O

Using map to create a sequence

2012-08-04 Thread Russel Winder
auto a = map!((a)=2*a)(iota(10)); Appears to do exactly what is says on the can. However, whilst: auto threads = new Thread [ numberOfThreads ] ; foreach ( i ; 0 .. numberOfThreads ) { auto closedPartialSum ( ) { immutable ii = i ; return delegate ( ) { partialSum ( ii ,

Return doesn't really return

2012-08-04 Thread Jacob Carlborg
I have a piece of code that looks like this: https://github.com/jacob-carlborg/dstep/blob/master/clang/Visitor.d#L168 If I change that first function to look like this: @property ParamCursor first () { assert(any, Cannot get the first parameter of an empty parameter list); foreach

Re: Inconsistency with function pointers

2012-08-04 Thread anonymous
On Saturday, 4 August 2012 at 15:23:39 UTC, Russel Winder wrote: [...] I can do: [...] auto f() { return delegate () { writeln(Hello World.); }; } auto t = new Thread(f); [...] However: [...] auto t = new Thread( delegate () { return delegate () {

Random Numbers

2012-08-04 Thread Ralph Main
Gotchas! The module std.random documentation doesn't work as per the examples. The example shows getting a random number by the following code does not work: code // Generate a uniformly-distributed integer in the range [0, 14] auto i = uniform(0, 15); // Generate a

Re: Return doesn't really return

2012-08-04 Thread Andrej Mitrovic
On 8/4/12, Jacob Carlborg d...@me.com wrote: Have I done a mistake somewhere or is this a bug in DMD? Could be related to: http://d.puremagic.com/issues/show_bug.cgi?id=7453 IOW, maybe your opApply function needs fixing?

Re: Random Numbers

2012-08-04 Thread Philippe Sigaud
On Sat, Aug 4, 2012 at 6:40 PM, Ralph Main rmain1...@live.com wrote: Hello Ralph, The module std.random documentation doesn't work as per the examples. The example shows getting a random number by the following code does not work: (snip) Both code samples you gave work perfectly for me (DMD

Re: Random Numbers

2012-08-04 Thread bearophile
Ralph Main: The module std.random documentation doesn't work as per the examples. The example shows getting a random number by the following code does not work: code // Generate a uniformly-distributed integer in the range [0, 14] auto i = uniform(0, 15); // Generate a

Re: Return doesn't really return

2012-08-04 Thread Timon Gehr
On 08/04/2012 06:23 PM, Jacob Carlborg wrote: I have a piece of code that looks like this: https://github.com/jacob-carlborg/dstep/blob/master/clang/Visitor.d#L168 If I change that first function to look like this: @property ParamCursor first () { assert(any, Cannot get the first parameter of

Re: Random Numbers

2012-08-04 Thread Ralph Main
On Saturday, 4 August 2012 at 16:59:09 UTC, Philippe Sigaud wrote: On Sat, Aug 4, 2012 at 6:40 PM, Ralph Main rmain1...@live.com wrote: Hello Ralph, The module std.random documentation doesn't work as per the examples. The example shows getting a random number by the following code does not

Re: Random Numbers

2012-08-04 Thread Ralph Main
On Saturday, 4 August 2012 at 17:02:19 UTC, bearophile wrote: Ralph Main: The module std.random documentation doesn't work as per the examples. The example shows getting a random number by the following code does not work: code // Generate a uniformly-distributed integer in the range

Re: Random Numbers

2012-08-04 Thread Ralph Main
On Saturday, 4 August 2012 at 17:45:19 UTC, Ralph Main wrote: On Saturday, 4 August 2012 at 17:02:19 UTC, bearophile wrote: Ralph Main: The module std.random documentation doesn't work as per the examples. The example shows getting a random number by the following code does not work: code

Re: Return doesn't really return

2012-08-04 Thread Jacob Carlborg
On 2012-08-04 19:08, Timon Gehr wrote: int opApply (Delegate dg) { auto result = clang_visitChildren(cursor, visitorFunction,cast(CXClientData) dg); return result == CXChildVisitResult.CXChildVisit_Break ? 1 : 0; // culprit } Yes, right. I forgot about that. The Clang API doesn't

Re: Inconsistency with function pointers

2012-08-04 Thread Jacob Carlborg
On 2012-08-04 18:41, Russel Winder wrote: Isn't there an overload for function and one for delegate? threadFunctionPointerUnnamed.d(5): Error: constructor core.thread.Thread.this called with argument types: ((void function())) matches both: core.thread.Thread.this(void

Re: Inconsistency with function pointers

2012-08-04 Thread David Nadlinger
On Saturday, 4 August 2012 at 15:23:39 UTC, Russel Winder wrote: trial.d(7): Error: constructor core.thread.Thread.this (void function() fn, ulong sz = cast(ulong)0) is not callable using argument types (void delegate() delegate() pure nothrow @safe) Failed: 'dmd' '-v' '-o-' 'trial.d' '-I.'

Re: Inconsistency with function pointers

2012-08-04 Thread David Nadlinger
On Saturday, 4 August 2012 at 19:03:30 UTC, David Nadlinger wrote: In your first example is that […] Darn, make this »In your first example, …«.

Re: Return doesn't really return

2012-08-04 Thread Timon Gehr
On 08/04/2012 08:54 PM, Jacob Carlborg wrote: On 2012-08-04 19:08, Timon Gehr wrote: int opApply (Delegate dg) { auto result = clang_visitChildren(cursor, visitorFunction,cast(CXClientData) dg); return result == CXChildVisitResult.CXChildVisit_Break ? 1 : 0; // culprit } Yes,

Re: Random Numbers

2012-08-04 Thread Philippe Sigaud
On Sat, Aug 4, 2012 at 7:27 PM, Ralph Main rmain1...@live.com wrote: I tried the code in just main() like bearophile's post, and it worked just fine. I also removed the new keyword from my program and it compiled. The error message that I got yesterday with the example code returned an

unittest vs exceptions?

2012-08-04 Thread Maxime Chevalier
I'd like to write some unit tests to check my software. Writing unittest blocks and putting assert statements in there seems easy enough, but I noticed that if the code I run in there throws an exception, I don't get the unit test failed message. How does unittest check for success/failure?

Re: unittest vs exceptions?

2012-08-04 Thread Jonathan M Davis
On Sunday, August 05, 2012 00:00:24 Maxime Chevalier wrote: I'd like to write some unit tests to check my software. Writing unittest blocks and putting assert statements in there seems easy enough, but I noticed that if the code I run in there throws an exception, I don't get the unit test

Re: unittest vs exceptions?

2012-08-04 Thread David Nadlinger
On Saturday, 4 August 2012 at 22:09:03 UTC, Jonathan M Davis wrote: On Sunday, August 05, 2012 00:00:24 Maxime Chevalier wrote: How does unittest check for success/failure? Does assert throw a special kind of error class when it fails? How would you check that some code didn't throw an

Re: Random Numbers

2012-08-04 Thread Ralph Main
On Saturday, 4 August 2012 at 20:22:23 UTC, Philippe Sigaud wrote: On Sat, Aug 4, 2012 at 7:27 PM, Ralph Main rmain1...@live.com wrote: I tried the code in just main() like bearophile's post, and it worked just fine. I also removed the new keyword from my program and it compiled. The

Re: unittest vs exceptions?

2012-08-04 Thread Jonathan M Davis
On Sunday, August 05, 2012 00:15:49 David Nadlinger wrote: A failed unit test really just means that a unit test block is left via an exception. Currently, it just bubbles up to the druntime main(), where it is printed to console and causes a non-zero exit code, but future unit test frameworks

Re: unittest vs exceptions?

2012-08-04 Thread Era Scarecrow
On Saturday, 4 August 2012 at 22:15:53 UTC, David Nadlinger wrote: On Saturday, 4 August 2012 at 22:09:03 UTC, Jonathan M Davis wrote: On Sunday, August 05, 2012 00:00:24 Maxime Chevalier wrote: How does unittest check for success/failure? Does assert throw a special kind of error class when

Re: unittest vs exceptions?

2012-08-04 Thread Tobias Pankrath
On Saturday, 4 August 2012 at 22:26:26 UTC, Jonathan M Davis wrote: On Sunday, August 05, 2012 00:15:49 David Nadlinger wrote: A failed unit test really just means that a unit test block is left via an exception. Currently, it just bubbles up to the druntime main(), where it is printed to

Re: unittest vs exceptions?

2012-08-04 Thread Jonathan M Davis
On Sunday, August 05, 2012 01:01:03 Tobias Pankrath wrote: you can do it as a library solution just fine. You shouldn't have to use a library to get named unit tests, since unit testing is built into D, and the lack of name unit tests is a real problem for stack traces and the like. It was

Re: unittest vs exceptions?

2012-08-04 Thread Maxime Chevalier
These improvements would be very nice. The unit test framework, as it is, is rather underpowered. Exceptions could also use more documentation on the D website. I heard there was some exception chaining mechanism, but I can't even seem to find any info on the Error class. You shouldn't have

Re: unittest vs exceptions?

2012-08-04 Thread Jonathan M Davis
On Sunday, August 05, 2012 01:43:55 Maxime Chevalier wrote: These improvements would be very nice. The unit test framework, as it is, is rather underpowered. Exceptions could also use more documentation on the D website. I heard there was some exception chaining mechanism, but I can't even

casting from variant

2012-08-04 Thread cal
In the following code: Variant j; j = 1.0; // make it a double auto x = cast(float)(j.get!(double)); // fail: cannot cast j.get!(double) auto y = cast(float)x; // fine The first attempt to cast doesn't compile, but the second less-direct cast is OK. Is that a bit strange?

Re: Inconsistency with function pointers

2012-08-04 Thread Russel Winder
On Sat, 2012-08-04 at 21:03 +0200, David Nadlinger wrote: […] You are trying to pass a delegate which returns a delegate – this isn't going to work. ;) But that is my whole point, it does a lot of the time, and it depends on whether you are working with named functions and delegates or with