Thread overview
[Issue 6854] New: delegates does not work outside of object
Oct 25, 2011
Timofei Bolshakov
Oct 25, 2011
Jonathan M Davis
Oct 26, 2011
Timofei Bolshakov
October 25, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6854

           Summary: delegates does not work outside of object
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: tbolsh@gmail.com


--- Comment #0 from Timofei Bolshakov <tbolsh@gmail.com> 2011-10-25 16:30:25 PDT ---
Dmd generate an error where it did not before (~2.032) and as far as I understand the language where it should not.

dmd version: 2.055
OS Linux

Here is the piece of code: ________________________________________________________________ #!/usr/bin/rdmd

import  std.datetime;

alias bool delegate (  )                       predicate;

predicate wait_for_seconds( immutable uint seconds = 0 ){
    immutable long start = SysTime.stdTime;
    return delegate (){ return seconds==0 ? true : ( (SysTime.stdTime - start)
< seconds*10_000_000L ); };
}

void main( string [] args ){
}
______________________________________________________________
here is what compiler tells:
./tst.d(8): Error: 'this' is only defined in non-static member functions, not
__dgliteral1

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 25, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6854


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jmdavisProg@gmx.com
         Resolution|                            |INVALID


--- Comment #1 from Jonathan M Davis <jmdavisProg@gmx.com> 2011-10-25 16:51:29 PDT ---
That code is definitely wrong. stdTime is not a static function. It must be called on an object of type SysTime, not on the type itself. You probably want something more like this:

import  std.datetime;

alias bool delegate (  )                       predicate;

predicate wait_for_seconds( immutable uint seconds = 0 )
{
    auto start = Clock.currTime();

    return delegate ()
    {
        return seconds == 0 ? true
                            : Clock.currTime() - start <
dur!"seconds"(seconds);
    };
}

void main( string [] args )
{
}

though whether that does exactly what you want, I don't know (e.g. I would have that that you'd want to use >, not < given the function name, but your code has <).

You might want to check out this article if you want know more about std.datetime beyond just reading the docs: http://d-programming-language.org/intro-to-datetime.html

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 26, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6854



--- Comment #2 from Timofei Bolshakov <tbolsh@gmail.com> 2011-10-25 20:11:42 PDT ---
Sorry - you are 100% right - filed a bug too fast. really sorry.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------