Monkey1 to Monkey2


A quick list of things to consider when converting monkey1 code to monkey2…

Strict mode not an option!

All functions that return something must return something! In monkey1, you could omit return statements even in functions that returned non-void. Not so in monkey2 (although this isn’t actually implemented in the compiler yet..).

Variables no longer default to int – all variable declarations must either specify a type, or be initialized with a value, eg:

Method and function declarations can still omit a return type, however the default return type in monkey2 is void (as opposed to int in monkey1).

The monkey1 shortcut type specifiers (eg: % for int and # for float) are not supported in monkey2 – you must use ‘:Int’, ‘:Float’ etc.

Using namespaces and importing files

Monkey2 adds a ‘namespace’ system to monkey1.

This basically means all declarations belong to some namespace. There are no ‘global’ declarations.

The easiest way to deal with this is to add this to the top of your source files:

This will allow you to access ALL decalarations in the std and mojo namespaces.

To import monkey2 source files into a build, use the preprocessor #Import directive, eg:

If you don’t specify an extension, #Import assumes ‘.monkey2’ so this actually imports “file2.monkey2”

Function call parameters must be enclosed in parenthesis

In monkey1, you could (usually…) omit the paranthesis around function parameters, eg:

In monkey2, this is not allowed – all function parameters must be enclosed in parenthesis, eg:

Array creation syntax changes

Monkey1 allowed a ‘quick’ form of array constructor:

In monkey2, you need to use the longer (but equivalent) form:

Also, to create an array with existing elements you must now use:

This replaces the old [value0,value1,value2…] syntax.

Virtual and overriding methods must be explicitly marked

In monkey1, all non-final methods are automatically virtual and can (sometimes inadvertently) dynamically override existing methods. In monkey2, virtual and overriding methods must be marked as such, eg:

Property syntax changes

Code that declares properties will need to use the new syntax. Instead of this…

…you will to need to use…

End-of-line handling

Monkey2 is currently VERY strict about end-of-lines.

All ‘block’ declarations (Class, Method, Property, Function) and block statements (If, While, Repeat, Select) must be of the following form:


_header_ and _footer_ must start on a new line, and be the only thing on that line. Declarations can no longer be ‘mashed up’ onto a single line. For example:

Multiple statements can appear on a single line, as long as they are separated by the statement separator token ‘;’, eg:

Finally, monkey2 ignores any end-of-line tokens that appear after any of the following: ‘(‘, ‘[‘ and ‘,’. This allows you to split function parameter lists and auto array elements over mulitple lines.

No fancy slices.

Instead of this…

…use this…


Liked it? Take a second to support Monkey 2 on Patreon!

2 thoughts to “Monkey1 to Monkey2”

Leave a Reply