Re: memoize (is this a fix for overloading?)

2011-01-05 Thread Max Samukha
On 01/05/2011 02:12 PM, Lars T. Kyllingstad wrote: On Wed, 05 Jan 2011 13:40:05 +0200, Max Samukha wrote: On 01/05/2011 12:24 PM, Lars T. Kyllingstad wrote: On Wed, 05 Jan 2011 12:07:50 +0200, Max Samukha wrote: On 01/05/2011 11:21 AM, Lars T. Kyllingstad wrote: On Tue, 04 Jan 2011 17:06:45

Re: memoize (is this a fix for overloading?)

2011-01-05 Thread Lars T. Kyllingstad
On Wed, 05 Jan 2011 13:40:05 +0200, Max Samukha wrote: > On 01/05/2011 12:24 PM, Lars T. Kyllingstad wrote: >> On Wed, 05 Jan 2011 12:07:50 +0200, Max Samukha wrote: >> >>> On 01/05/2011 11:21 AM, Lars T. Kyllingstad wrote: On Tue, 04 Jan 2011 17:06:45 -0600, Andrei Alexandrescu wrote: >

Re: memoize (is this a fix for overloading?)

2011-01-05 Thread Max Samukha
On 01/05/2011 12:24 PM, Lars T. Kyllingstad wrote: On Wed, 05 Jan 2011 12:07:50 +0200, Max Samukha wrote: On 01/05/2011 11:21 AM, Lars T. Kyllingstad wrote: On Tue, 04 Jan 2011 17:06:45 -0600, Andrei Alexandrescu wrote: On 1/4/11 4:49 PM, %u wrote: There's still the risk of keeping multiple

Re: memoize (is this a fix for overloading?)

2011-01-05 Thread Lars T. Kyllingstad
On Wed, 05 Jan 2011 12:07:50 +0200, Max Samukha wrote: > On 01/05/2011 11:21 AM, Lars T. Kyllingstad wrote: >> On Tue, 04 Jan 2011 17:06:45 -0600, Andrei Alexandrescu wrote: >> >>> On 1/4/11 4:49 PM, %u wrote: > There's still the risk of keeping multiple hashes. Consider: > ulong fun(

Re: memoize (is this a fix for overloading?)

2011-01-05 Thread Max Samukha
On 01/05/2011 11:21 AM, Lars T. Kyllingstad wrote: On Tue, 04 Jan 2011 17:06:45 -0600, Andrei Alexandrescu wrote: On 1/4/11 4:49 PM, %u wrote: There's still the risk of keeping multiple hashes. Consider: ulong fun(ulong n) { ... } alias memoize!fun mfun; mfun(5); // creates hash ulong[in

Re: memoize (is this a fix for overloading?)

2011-01-05 Thread Lars T. Kyllingstad
On Tue, 04 Jan 2011 17:06:45 -0600, Andrei Alexandrescu wrote: > On 1/4/11 4:49 PM, %u wrote: >>> There's still the risk of keeping multiple hashes. Consider: >> >>> ulong fun(ulong n) { ... } >>> alias memoize!fun mfun; >> >>> mfun(5); // creates hash ulong[int] >>> mfun(5u); // creates hash ulon

Re: memoize (is this a fix for overloading?)

2011-01-04 Thread %u
It seems to me that this is an unsolvable problem without built-in compiler support using __traits(getOverloads, Func), since without knowing all the overloads of a function, you can't possibly write a template to widen the arguments to the correct parameter types. (The current getOverloads needs a

Re: memoize (is this a fix for overloading?)

2011-01-04 Thread Andrei Alexandrescu
On 1/4/11 4:49 PM, %u wrote: There's still the risk of keeping multiple hashes. Consider: ulong fun(ulong n) { ... } alias memoize!fun mfun; mfun(5); // creates hash ulong[int] mfun(5u); // creates hash ulong[uint] mfun('5'); // creates hash ulong[char] Ohhh I see... so you're basically

Re: memoize (is this a fix for overloading?)

2011-01-04 Thread Michal Minich
On Tue, 04 Jan 2011 22:49:11 +, %u wrote: > (An unrelated side note: I'm new to newsgroups, and I was wondering, > what program do people mainly use for communication? I'm using the web > interface, but do most people use Thunderbird or something? Thank you!) Also outlook express, omea reader

Re: memoize (is this a fix for overloading?)

2011-01-04 Thread Jonathan M Davis
On Tuesday, January 04, 2011 14:49:11 %u wrote: > > There's still the risk of keeping multiple hashes. Consider: > > > > ulong fun(ulong n) { ... } > > alias memoize!fun mfun; > > > > mfun(5); // creates hash ulong[int] > > mfun(5u); // creates hash ulong[uint] > > mfun('5'); // creates hash ulon

Re: memoize (is this a fix for overloading?)

2011-01-04 Thread %u
> There's still the risk of keeping multiple hashes. Consider: > ulong fun(ulong n) { ... } > alias memoize!fun mfun; > mfun(5); // creates hash ulong[int] > mfun(5u); // creates hash ulong[uint] > mfun('5'); // creates hash ulong[char] Ohhh I see... so you're basically looking for a compile-ti

Re: memoize (is this a fix for overloading?)

2011-01-04 Thread Andrei Alexandrescu
On 1/4/11 2:57 PM, %u wrote: Hi all, How does this work, with respect to overloading? auto memo(alias Fn, TParams...)(TParams args) if (isCallable!(Fn)) { static typeof(Func(args))[Tuple!(TParams)] cache; auto key = tuple(args); return key in cache ? cache[key] : (cache[key] = Fu

Re: memoize (is this a fix for overloading?)

2011-01-04 Thread %u
Hi all, How does this work, with respect to overloading? auto memo(alias Fn, TParams...)(TParams args) if (isCallable!(Fn)) { static typeof(Func(args))[Tuple!(TParams)] cache; auto key = tuple(args); return key in cache ? cache[key] : (cache[key] = Func(args)); } uint fib(uint n) { r