Variant Function

About Monkey 2 Forums Monkey 2 Programming Help Variant Function

This topic contains 2 replies, has 2 voices, and was last updated by  cocon 2 weeks, 1 day ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #16232


    Looking through the documentation I came across Variants which sound pretty handy. I noticed an example that demonstrated it was possible for Variants to box functions.

    This code was taken directly from the language reference (I removed a few lines that boxed other values). Unfortunately this doesn’t compile, the output is below.

    I haven’t had a chance to look at the source code yet but I assume this is either a bug or I’m doing something wrong?




    Now testing both ways and it only works with Lambdas.

    I don’t know exactly what are the internal implementation of Monkey.
    Is this a bug or there’s a technical reason to do so?



    However keep in mind if, instead of assigning a function to a variant (it seems like a convenient way) you can alternatively go with the object oriented route (eg: Strategy Pattern) or perhaps if you are more like of a “functional programming guy” use function pointers instead.



    However now as I testing it seems that Main() has a very special protection that makes it called only once, no matter where you try to call it again and again it makes no point.

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

You must be logged in to reply to this topic.