Alternative Syntax for lambda-statements

Bug #602550 reported by Sebastian Lai
4
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Falcon
Won't Fix
Undecided
Unassigned

Bug Description

(This is not exactly a bugreport, but merely a feature-request)

Currently, the Lambda statement looks like this:

    someFunction(function(arguments)
        while doSomethingWith(arguments)
            somethingompletelyDifferent()
            // ...
        end
    end)

At first expression, this is perfectly fine. The Lua Language uses a similar solution, however it has one major flaw: Instead of evaluating the anonymous function, an additional call (as '()') has to be appended:

    someFunction(function(arguments)
        while doSomethingWith(arguments)
            somethingompletelyDifferent()
            // ...
        end
    end(x))

I'm not sure if this is behaviour is intended like this, but it's not very obvious.
That's why i'd prefer an alternative syntax for lambda statements:

    /*
    * lambda might be a keyword
    * note the '[]'
    */
    someFunction(lambda[arguments] {
        while doSomethingWith(arguments)
            // ...
        end
    })

I believe that would make creating lambdas alot more obvious and behave more like in other languages.

Again, this is not exactly a bug, but a feature request.

Tags: lambda
Revision history for this message
gniccolai (gc-niccolai) wrote :

Yes, it is intended exactly so.

Also, {p1...pn => statement...} is currently equivalent to function( p1...pn); statement...; end.

Moreover, I think you misunderstood what function (p1...pn); statement; end (p1...pn) does. It doesn't return your lambda; it executes it on the spot and returns its return value. So, the expression you are searching for is exactly the first one you posted.

Finally, we had a lambda keyword, and it was removed.

Changed in falconpl:
status: New → Won't Fix
Revision history for this message
Sebastian Lai (user17) wrote :

> Yes, it is intended exactly so.
Okay... nonetheless I think it's a rather "unique" behaviour.

> Also, {p1...pn => statement...} is currently equivalent to function( p1...pn); statement...; end.
Would that mean:
    {someArg, someOtherArg =>
        while doThingsWith(someArg) and whatNot(someOtherArg)
            code()
        end}

? If that's the case, then it would be even more unique (I probably just misunderstood it somehow)...

Revision history for this message
gniccolai (gc-niccolai) wrote : Re: [Bug 602550] Re: Alternative Syntax for lambda-statements

In data mercoledì 07 luglio 2010 10:38:12, hai scritto:
> > Yes, it is intended exactly so.
>
> Okay... nonetheless I think it's a rather "unique" behaviour.
>
> > Also, {p1...pn => statement...} is currently equivalent to function(
> > p1...pn); statement...; end.
>
> Would that mean:
> {someArg, someOtherArg =>
> while doThingsWith(someArg) and whatNot(someOtherArg)
> code()
> end}
>
> ? If that's the case, then it would be even more unique (I probably just
> misunderstood it somehow)...

Yes. And it is unique, indeed.

However, practically. I dont' see how

lambda[ a, b, c ] {
   ... do things with abc ...
}

could improve the grammar

function( a, b, c )
   ... do things with abc ...
end

which does exactly the same thing.

Gian.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.