[REQUEST] Add 'With…End With' Statement in Monkey2 language

About Monkey 2 Forums Monkey 2 Development [REQUEST] Add 'With…End With' Statement in Monkey2 language

This topic contains 9 replies, has 6 voices, and was last updated by  seyhajin 11 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
  • #9828



    Can you add the statement “With … End With” for the language Monkey2?
    It can be a good addition to the language, moreover, it allows to clarify the source code and avoids redundancies. Especially with objects that contains other objects, it can be very long … 🙂
    I have no idea about the work that it represents, I let you decide.

    Here is an example of an implementation in Visual Basic: https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/with-end-with-statement

    Example VB Code :

    Translate to Monkey2


    Mark Sibly

    Still can’t decide how much/if I like that.

    It doesn’t help that the example doesn’t make any sense (where is InfoLabel declared?) but I can’t really see myself using it, I guess if I had to initialize a massive struct or something…

    Any other opinions on this? I think Amiga blitz actually had something like this, but it looks like it didn’t have much of an impact on me!



    Ahh I see it’s just so you don’t have to reference the class you’re messing with over and over as far as I can tell.

    GML from Game Maker as something like this only the syntax is a bit changed, it allows you to edit collections of objects by using “all” or a single parent class.

    This would be useful for some but I personally don’t really think it would be too necessary.
    Very cool concept though!



    “With statement” work with ObjectClass expression only (class if you want use static function/variable or instance of class) and use “.” (dot) or “->”, if object’s pointer, in the block to avoid rewrite ObjectClass.

    Syntax :

    [ObjectExpression] : Required. An expression that evaluates to an object or class/struct
    [Statements] : Optional. One or more statements between ‘With’ and ‘End’ that may refer to members of an objects that’s produced by the evaluation of [ObjectExpression]
    [End] : Required. Terminates the definition of the “With” block

    Monkey2 example :



    Isnt this the same and less verbose?



    Obviously this has a real interest if there are many members called for the same object, or calling the members of these nested objects. In use it will always be much less verbose.



    mmm, good concept.

    Really bad code example though.

    This is a much better example of using that class concept:


    You don’t need to use ‘with’

    Just initialise with new and use add. there is no need to have functions cluttering up everything…



    The right subject is to request to integrate “With” statement in Monkey2 language, no how to use an equivalent. 🙂

    Do you think this is possible to add this in Monkey2 simply?


    Simon Armstrong

    Having two ways of doing something makes a language more complicated not simpler.

    If you adopt use of methods for modifying objects and avoid any reference of fields from outside an objects implementation the programs you create will be easier to expand and maintain.



    The “With … End” statement is considered as a “helper” to have a clearer and less verbose source code, neither more nor less, it does not modify the control structures. A bit like the use of “Alias” which allows to “simplify” a type of variable or function. For example, you can write “Rect <Float>” to “Rectf” in your “Rect <Float>” and with “Alias”, and nothing prevents you from writing “Rect <Float>” elsewhere of your application. There are two different ways to use it but quite compatible.

    1. You define an “ObjectClass” with “With” keyword as the current “Object” to use in the block
    2. Inside the “With” block, you use (dot) “.MyMethod or .MyProperty” directly without rewriting your declared “With”
    3. “End”
Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.