www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4665] New: map with no automatic closure

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4665

           Summary: map with no automatic closure
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



This D2 program seems correct:


import std.algorithm: map;
void main() {
    int n = 2;
    map!((double x){ return x * n; })([1.0, 2.0]);
}


But DMD 2.048 prints at run time:
object.Error: Access Violation


On IRC #D jA_cOp has commented that TDPL says that the compiler should
automatically choose delegate over function if it accesses its outer lexical
scope.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 17 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4665


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



18:18:53 PDT ---
It does seem to be a delegate after all. If you try to evaluate it right there
it shows (notice the parantheses after the lambda definition):

import std.algorithm: map;

void main() 
{
    int n = 2;
    map!( (double x){ return x * n; }() )([1.0, 2.0]);
}

Errors:

test.d(10): Error: expected 1 function arguments, not 0
test.d(10): Error: cannot evaluate delegate double(double x)
{
return x * cast(double)n;
}
() at compile time


This seems like a compiler bug. If you use a string instead, then it will work:

import std.algorithm: map;

void main() 
{
    string n = "2";
    map!( (string x){ return x ~ n; } )(["1.0", "2.0"]);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 29 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4665


Brad Anderson <eco gnuk.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eco gnuk.net



The code works in DMD 2.060 beta.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 27 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4665


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




 The code works in DMD 2.060 beta.
Right. Closed. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 27 2012