Re: UFCS in template function

2013-08-29 Thread Jacob Carlborg
On 2013-08-29 22:02, Andrej Mitrovic wrote: However it does work for local imports (I think this was new in 2.063): void main() { import std.range; assert([].empty); // ok } "empty" is declared at module scope. -- /Jacob Carlborg

Stride in foreach ranges

2013-08-29 Thread Paul Jurczak
Is there a better way to express a range with stride than this: foreach (i; iota(0, N, 2)) Maybe something similar to F# syntax: foreach (i; 0..2..N) I found this thread suggesting syntax improvement http://forum.dlang.org/thread/bug-411...@http.d.puremagic.com/issues/ but I don't think it p

Re: Code from a Rosetta Code Task

2013-08-29 Thread Ali Çehreli
On 08/29/2013 08:53 PM, Meta wrote: > However, after some fiddling, it seems that this is actually not usable with > anonymous functions, or at least, I couldn't find a way to do it. Borrowing the "self" trick from the existing solution, the following satisfies all of the requirements: int

Re: Code from a Rosetta Code Task

2013-08-29 Thread Meta
On Thursday, 29 August 2013 at 22:01:38 UTC, H. S. Teoh wrote: That's clever, but I'm not sure I understand the bit about anonymous functions? You don't need anonymous functions to have recursion. Sorry, that came out all wrong. What I meant was that it's neat to be able to do anonymous recur

Re: Regarding emplace, arrays, and helper functions

2013-08-29 Thread Ali Çehreli
On 08/29/2013 05:20 AM, Andrej Mitrovic wrote: > The emplace docs state that the chunk where to store the class object > instance needs to be aligned to the class type alignment. But it > doesn't say much on how to get this alignment from a class (we could > add a note about using the classInstan

Re: class destructors and sub-objects

2013-08-29 Thread Ali Çehreli
On 08/29/2013 06:58 AM, d coder wrote:> Greetings > > I have a question on class destructor method. D documentation for > destructors says: > > "The garbage col­lec­tor is not guar­an­teed to run the de­struc­tor for > all un­ref­er­enced ob­jects. Fur­ther­more, the order in which the garbage >

Re: Code from a Rosetta Code Task

2013-08-29 Thread Ali Çehreli
On 08/29/2013 04:37 PM, bearophile wrote: > H. S. Teoh: > >> Also, this is a pretty poor algorithm for generating the Fibonacci >> series, > > I know, but you must do what the tasks asks you: > > http://rosettacode.org/wiki/Anonymous_recursion > > Bye, > bearophile Hm... Like some of the other l

Re: Code from a Rosetta Code Task

2013-08-29 Thread H. S. Teoh
On Fri, Aug 30, 2013 at 01:37:39AM +0200, bearophile wrote: > H. S. Teoh: > > >Also, this is a pretty poor algorithm for generating the Fibonacci > >series, > > I know, but you must do what the tasks asks you: > > http://rosettacode.org/wiki/Anonymous_recursion [...] OK I see. I wish we could

Re: Code from a Rosetta Code Task

2013-08-29 Thread bearophile
H. S. Teoh: Also, this is a pretty poor algorithm for generating the Fibonacci series, I know, but you must do what the tasks asks you: http://rosettacode.org/wiki/Anonymous_recursion Bye, bearophile

Re: Code from a Rosetta Code Task

2013-08-29 Thread H. S. Teoh
On Thu, Aug 29, 2013 at 03:00:09PM -0700, H. S. Teoh wrote: > On Thu, Aug 29, 2013 at 11:00:49PM +0200, Robik wrote: > > On Thursday, 29 August 2013 at 18:57:58 UTC, Meta wrote: > > >uint fib(in uint n) pure nothrow { > > >immutable self = &__traits(parent, {}); > > >return (n < 2) ? n : se

Re: Code from a Rosetta Code Task

2013-08-29 Thread H. S. Teoh
On Thu, Aug 29, 2013 at 11:00:49PM +0200, Robik wrote: > On Thursday, 29 August 2013 at 18:57:58 UTC, Meta wrote: > >uint fib(in uint n) pure nothrow { > >immutable self = &__traits(parent, {}); > >return (n < 2) ? n : self(n - 1) + self(n - 2); > >} > > > >I came across this while browsing

Re: Checking if UFCS function exists for a specific type

2013-08-29 Thread Rory McGuire
On Thursday, 29 August 2013 at 21:06:04 UTC, Rory McGuire wrote: Hi all, I've got this little ctfe template function that checks if a function called member with first argument T exists. Its for checking if a type has a custom encoder. bool hasUFCSmember(T, string member)() { T v; /

Checking if UFCS function exists for a specific type

2013-08-29 Thread Rory McGuire
Hi all, I've got this little ctfe template function that checks if a function called member with first argument T exists. Its for checking if a type has a custom encoder. bool hasUFCSmember(T, string member)() { T v; // would be nice if we could use ParameterTypeTuple to get the fir

Re: Code from a Rosetta Code Task

2013-08-29 Thread Robik
On Thursday, 29 August 2013 at 18:57:58 UTC, Meta wrote: uint fib(in uint n) pure nothrow { immutable self = &__traits(parent, {}); return (n < 2) ? n : self(n - 1) + self(n - 2); } I came across this while browsing Rosetta Code. It's really cool how you can do recursion without anonymo

Re: UFCS in template function

2013-08-29 Thread Andrej Mitrovic
On 8/29/13, Jacob Carlborg wrote: > UFCS only works for module level functions. However it does work for local imports (I think this was new in 2.063): void main() { import std.range; assert([].empty); // ok }

Re: Question about garbage collector

2013-08-29 Thread Brian Rogoff
On Wednesday, 28 August 2013 at 21:28:11 UTC, bioinfornatics wrote: Hi everyone, yesterday i read an article into a french linux journal that in some years garbage collector will disapear. Why ? he explain in very very short as: -- - Moore's law will be not anymore tru

Re: Question about garbage collector

2013-08-29 Thread Jacob Carlborg
On 2013-08-29 16:20, qznc wrote: Also, be careful about the problem domain. There will be enough domains left in some years, where garbage collection is the better tradeoff. Just think about all the domains where Python,Ruby,etc are popular now. The interesting field is mobile, though. Android's

Code from a Rosetta Code Task

2013-08-29 Thread Meta
uint fib(in uint n) pure nothrow { immutable self = &__traits(parent, {}); return (n < 2) ? n : self(n - 1) + self(n - 2); } I came across this while browsing Rosetta Code. It's really cool how you can do recursion without anonymous functions (and this will actually not work if you make

Re: UFCS in template function

2013-08-29 Thread ixid
On Thursday, 29 August 2013 at 06:23:32 UTC, Jacob Carlborg wrote: UFCS only works for module level functions. What is the reason for this limitation?

Re: dmd memory usage/static lib/algorithm bug?

2013-08-29 Thread H. S. Teoh
On Thu, Aug 29, 2013 at 01:46:03AM +0200, Marek Janukowicz wrote: > H. S. Teoh wrote: > > > On Thu, Aug 29, 2013 at 12:45:05AM +0200, Marek Janukowicz wrote: > >> H. S. Teoh wrote: > > [...] > >> > Oh, and BTW, are you on Linux 32-bit or 64-bit? Don't know if > >> > that makes a difference, but ju

Re: Question about garbage collector

2013-08-29 Thread qznc
On Wednesday, 28 August 2013 at 21:28:11 UTC, bioinfornatics wrote: Hi everyone, yesterday i read an article into a french linux journal that in some years garbage collector will disapear. Why ? he explain in very very short as: -- - Moore's law will be not anymore tru

class destructors and sub-objects

2013-08-29 Thread d coder
Greetings I have a question on class destructor method. D documentation for destructors says: "The garbage col­lec­tor is not guar­an­teed to run the de­struc­tor for all un­ref­er­enced ob­jects. Fur­ther­more, the order in which the garbage col­lec­tor calls de­struc­tors for un­ref­er­ence ob­

Re: Recommended ways to handle final classes

2013-08-29 Thread Joseph Rushton Wakeling
On 16/08/13 23:21, JS wrote: You can't get them both at the same time though, which you might just make _A final. The whole point of inheritance is to treat derived classes as if they were base classes. Sorry for delayed response here, I've been fairly heavily focused on other things. :-( I

Re: What is a concise way to test if floating point value is integral?

2013-08-29 Thread Simen Kjaeraas
On 2013-08-29, 10:25, Jonathan M Davis wrote: On Thursday, August 29, 2013 10:07:31 Paul Jurczak wrote: On Thursday, 29 August 2013 at 07:51:40 UTC, Jonathan M Davis wrote: [..] > as any integral value in a float will fit in an > int. [..] Will it? Most of them will not fit Sure, they will

Re: Regarding emplace, arrays, and helper functions

2013-08-29 Thread bearophile
A little related: http://d.puremagic.com/issues/show_bug.cgi?id=8873 Bye, bearophile

Regarding emplace, arrays, and helper functions

2013-08-29 Thread Andrej Mitrovic
The emplace docs state that the chunk where to store the class object instance needs to be aligned to the class type alignment. But it doesn't say much on how to get this alignment from a class (we could add a note about using the classInstanceAlignment template), or even how to use it to create e.

Re: What is a concise way to test if floating point value is integral?

2013-08-29 Thread JS
On Thursday, 29 August 2013 at 08:58:02 UTC, Paul Jurczak wrote: On Thursday, 29 August 2013 at 08:26:11 UTC, Jonathan M Davis wrote: On Thursday, August 29, 2013 10:07:31 Paul Jurczak wrote: On Thursday, 29 August 2013 at 07:51:40 UTC, Jonathan M Davis wrote: [..] > as any integral value in a

Re: What is a concise way to test if floating point value is integral?

2013-08-29 Thread anonymous
On Thursday, 29 August 2013 at 08:26:11 UTC, Jonathan M Davis wrote: On Thursday, August 29, 2013 10:07:31 Paul Jurczak wrote: On Thursday, 29 August 2013 at 07:51:40 UTC, Jonathan M Davis wrote: [..] > as any integral value in a float will fit in an > int. [..] Will it? Most of them will not

Re: What is a concise way to test if floating point value is integral?

2013-08-29 Thread Paul Jurczak
On Thursday, 29 August 2013 at 08:26:11 UTC, Jonathan M Davis wrote: On Thursday, August 29, 2013 10:07:31 Paul Jurczak wrote: On Thursday, 29 August 2013 at 07:51:40 UTC, Jonathan M Davis wrote: [..] > as any integral value in a float will fit in an > int. [..] Will it? Most of them will not

Re: What is a concise way to test if floating point value is integral?

2013-08-29 Thread Jonathan M Davis
On Thursday, August 29, 2013 10:07:31 Paul Jurczak wrote: > On Thursday, 29 August 2013 at 07:51:40 UTC, Jonathan M Davis > wrote: > [..] > > > as any integral value in a float will fit in an > > int. > > [..] > > Will it? Most of them will not fit Sure, they will. float has 32 bits, just like

Re: What is a concise way to test if floating point value is integral?

2013-08-29 Thread Paul Jurczak
On Thursday, 29 August 2013 at 07:51:40 UTC, Jonathan M Davis wrote: [..] as any integral value in a float will fit in an int. [..] Will it? Most of them will not fit, but cast to int produces nonsensical value anyway as in this example: cast(int)float.max With to!int you get a proper warn

Re: What is a concise way to test if floating point value is integral?

2013-08-29 Thread Jonathan M Davis
On Thursday, August 29, 2013 08:50:47 Paul Jurczak wrote: > On Thursday, 29 August 2013 at 06:23:18 UTC, Jonathan M Davis > > wrote: > > On Thursday, August 29, 2013 07:47:16 Paul Jurczak wrote: > >> I'm writing this rather ugly: > >> > >> sqrt(cast(float)D) != round(sqrt(cast(float)D) > >> > >>