Local scope lambdas

About Monkey 2 Forums Monkey 2 Programming Help Local scope lambdas

This topic contains 6 replies, has 5 voices, and was last updated by  cocon 2 years, 8 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #2765

    cocon
    Participant

    I would like to know how I can reference str variable inside the append lambda.

    #2766

    Mark Sibly
    Keymaster

    You need to declare ‘str’ before the lamba, not after.

    #2782

    MikeHart
    Participant

    Mark, I think he did, or? He got the error inside the append function.

    #2785

    DruggedBunny
    Participant

    Yeah, the relevant code is:

    Don’t know much about lambdas in practice, but that to me looks like it ‘should’ work.

    #2798

    peterigz
    Participant

    I’m not sure what the variable scope is when it comes to lambdas in monkey 2, I know that would work in javascript, but it’s probably out of scope here, unless it’s a bug…

    #2806

    Mark Sibly
    Keymaster

    Forgot to also mention, you cannot modify ‘captured’ variables inside a lambda, ie: this should give an error:

     

    A lambda effectively gets a ‘copy’ of outer locals at the time the lambda is evaluated. So this..

    …will print ‘0’.

    #2831

    cocon
    Participant

    The ideal lambdas have the function purity concept (that no data modifications are allowed). I don’t know if Monkey uses that design indeed.

    What I had more in mind was the C# concept of Action and Func that modify variables. Perhaps C++ as well by using the ampersand operator.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.