www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Nested Inferred Templates Don't Work?

reply Mehrdad <wfunction hotmail.com> writes:
Hi!

Say I've got a piece of code like this, which gives me the longest line 
in a file:
     pipe!(readText, splitlines, map!((a) { return a.length; }), 
reduce!max)("Demo.txt");
The problem is, it doesn't work. Which is kind of a bummer. :(

Is there an **elegant** way to get around it?

Of course, I already know I can do this:
     pipe!(readText, splitlines, map!q{ a.length }, reduce!max)("Demo.txt");
but using strings is very ugly (IMO).

Thanks!
May 30 2011
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 5/31/11 1:04 AM, Mehrdad wrote:
 Hi!

 Say I've got a piece of code like this, which gives me the longest line
 in a file:
 pipe!(readText, splitlines, map!((a) { return a.length; }),
 reduce!max)("Demo.txt");
 The problem is, it doesn't work. Which is kind of a bummer. :(

 Is there an **elegant** way to get around it?

 Of course, I already know I can do this:
 pipe!(readText, splitlines, map!q{ a.length }, reduce!max)("Demo.txt");
 but using strings is very ugly (IMO).

 Thanks!

That's a bug in the compiler. You may want to try specifying the function literal with types, e.g. function size_t(string a) { return a.length; }. A bug report would be appreciated. Andrei
May 31 2011
parent Mehrdad <wfunction hotmail.com> writes:
== Quote from Andrei Alexandrescu (SeeWebsiteForEmail erdani.org)'s
article
 On 5/31/11 1:04 AM, Mehrdad wrote:
 Hi!

 Say I've got a piece of code like this, which gives me the


 in a file:
 pipe!(readText, splitlines, map!((a) { return a.length; }),
 reduce!max)("Demo.txt");
 The problem is, it doesn't work. Which is kind of a bummer. :(

 Is there an **elegant** way to get around it?

 Of course, I already know I can do this:
 pipe!(readText, splitlines, map!q{ a.length }, reduce!max)


 but using strings is very ugly (IMO).

 Thanks!

function literal with types, e.g. function size_t(string a) {

 a.length; }. A bug report would be appreciated.
 Andrei

That actually doesn't work either (it says it can't access the frame...). I filed a bug report: http://d.puremagic.com/issues/show_bug.cgi?id=6081 Thanks!
May 31 2011