Skip to content

release-0.7

Compare
Choose a tag to compare
@skx skx released this 03 Oct 03:56
· 197 commits to master since this release

The previous release updated the Monkey-language to support object-based method-calls - invoking methods against objects, with the methods being written in Go.

In this release it became possible to define object-methods in Monkey, and this is now used to implement as much as possible of the languages' standard-library in monkey itself. For example functions which were previously implemented in golang, such as string.toupper(), string.tolower(), string.replace(), are now implemented solely in monkey.

Migrating methods to monkey provides a good example of real code, as well as providing an opportunity to see which abilities/functions were missing.

One example of the migration inspiring new features is the changes inspired by writing string.toupper(). It is obvious we'd want to test if a character was lower-case - the natural way to write that would be:

  if ( c >= 'a' && c <= 'z' ) {
  }

Unfortunately the use of && inside conditionals wasn't available, so I had to add it! Porting the string.toupper() function from golang to monkey directly inspired three new features:

  • The use of && in conditional-tests.
  • The use of || in conditional-tests.
  • The function string.ord() and integer.chr()
    • Both used to add/subtract 32 - which is used in ASCII case-conversion.

The only significant new feature in this release is the implementation of the eval method, which allows monkey-code to be executed dynamically at run-time. With the addition of this new eval function it became possible to write a useful assert method, which has been done.

Using our new assert/eval functions the standard-library code which is implemented in monkey is now tested at run-time. This should ensures that future-bugs are caught earlier.

Finally there were the usual range of bug-fixes including the following:

  • Copies of constant-objects are modifiable now, as expected:
  • Nested for-loops work as expected:
  • The methods() function returns all (sorted) methods