Apple Blocks added to C++?

Nick Sabalausky a at a.a
Wed Sep 2 13:11:00 PDT 2009


"Walter Bright" <newshound1 at digitalmars.com> wrote in message 
news:h7mch9$l5v$1 at digitalmars.com...
> Mattias Holm wrote:
>> Walter Bright wrote:
>>> S. wrote:
>>> I find it strange that people are continuing to reinvent nested 
>>> functions in ugly ways.
>>
>> The blocks are not nested functions, they are more like closures.
>
> Nested functions do closures in a straightforward way, so by leaving off 
> nested functions they were forced to make an ugly syntax <g>. This is why 
> I shake my head in just not understanding the process that led to their 
> design.
>

My guess is that it's because closures and anonymous function literals seem 
to be "the hip new thing", and nested functions aren't (possibly in part 
because, and I'm not certain if this is even true or not, but maybe most of 
the imperative languages that do have nested functions don't treat nested 
functions as full closures?). That, combined with the fact that most 
language designers these days seem to be more intersted in providing 
one-and-only-one way to do something regarless of whether or not it gets in 
the way of pragmatism.

So their line of thinking is probably something like:

First: "Everyone else has anon func literals, we need them too."
Second: "Nested functions, you say? Why would we need those? We already have 
anon func literals that can just be assigned to a variable!"

Anyway, that's just my guess.

BTW, if you think the "nested funcs" most languages have are bad, you should 
see the Haxe version:

class EverythingMustBeInAClass_Natch
{
    var member:Int;
    void bar():Void
    {
        var local:Int;

        // Ok so far...
        local = 1;
        member = 1;

        // Holy crap, what happened?
        // (Although, to be fair, the ":Type" parts could
        // probably be omitted...but still...)
        var _this:EverythingMustBeInAClass_Natch = this;
        var nestedFunc:Int->String->Bool =
            function(a:Int, b:String):Bool
            {
                local = 1;
                _this.member = 1;
            }
    }
}

The scary thing is, Haxe still, overall, beats the crap out of PHP and AS2 
(that's why I've been using Haxe and have enough familiarity with it to keep 
whining about it at every opportunity ;) )





More information about the Digitalmars-d mailing list