Search code examples
dtype-inferencenested-function

D nested functions type inference


Does anyone know if subj will be implemented? At least, auto storage class for them? Thanks!


Solution

  • There are various problem with auto functions in general, so it could very well be that you can't do

    void main()
    {
        auto bar() { return "hello world"; }
    
        writeln(bar());
    }
    

    because of a bug with auto rather than it being as designed. I'm not sure what the exact plans for that are, though I would think that you would supposed to be able to use auto as the return type of a nested function. There is an enhancement request on it in either case.

    However, regardless of whether auto works with nested functions, you can declare a delegate in a similar manner:

    void main()
    {
        auto bar = () { return "hello world"; };
    
        writeln(bar());
    }
    

    So, the basic functionality is still there, even if the exact syntax that you were looking for doesn't currently work.