Closures?

This topic contains 3 replies, has 3 voices, and was last updated by  papgar 2 years, 8 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #4541

    skn3
    Participant

    Pretty excited to see that mx2 appears to support closures!

    Is the following code valid/safe in mx2?

    What are the consequences/penalties/performance-issues by doing this? For example, what is happening (internally) to name:String once CreateItem has returned?

    #4542

    Mark Sibly
    Keymaster

    Yep, that’s fine. I use stuff like this all over the place in Ted2 , eg: mojox.Action.

    name:String is ‘captured’ by the lamba, which effectively means it’s copied into a private area of the lamba. But since strings are immutable and reference counted, this is very cheap.

    #4544

    skn3
    Participant

    That is good news! Might be worth adding an example to the Lambda docs. I was going to do it in the online Manual, but it looks like comments are only available for modules?

     

    Here is how I am using it, very handy!

    #4545

    papgar
    Participant

    It would be nice to have more lambda examples in docs so we can see how this feature is useful for applications/games.

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

You must be logged in to reply to this topic.