MiniD


The MiniD programming language is a small, lightweight, extension language in the vein of Lua or Squirrel, but designed to be used mainly with the D programming language. It supports both object-oriented and imperative programming paradigms, as well as some simple functional aspects.
Distributed under the licence of zlib/libpng, MiniD is free software.

History

MiniD began in June 2006 as an idea for a statically-typed language, much like a stripped-down version of the D programming language. This is the reason for the name "MiniD". After work began on the compiler, the creator, Jarrett Billingsley, realized just how large a project this language was becoming, and decided to recast the language into something simpler to implement. The result was a Lua-like language with a C-style syntax. Over the next several months, MiniD acquired features from various languages, such as Squirrel-like classes, a D-like module system, and Lua-like collaborative multithreading. On August 1, 2007, after more than thirteen months of planning and programming, version 1.0 of the reference implementation was released. The version 1.0 language specification is frozen.
As of June 15, 2009, version 2 of MiniD has been released. Version 2 brings a major reimplementation of most of the library in order to support its own garbage collector rather than relying on the underlying D garbage collector, for better behavior in realtime applications such as games. Version 2 also brings several changes to the language and standard libraries.
The development of MiniD was stopped in June 2011 and used as the base for new language called Croc by the same author.

Features

MiniD provides a small but flexible set of data types, similar to that of Lua's or Squirrel's. Unlike Lua, MiniD provides explicit support for object-oriented programming with classes. MiniD also provides a module system and coroutines as core language features, like Lua. MiniD is garbage-collected, with support for first-class functions, closures, and tail recursion.
MiniD also tries to be more robust than typical dynamic languages, making it easier to catch bugs sooner. For example, it does not have implicit variable declarations and accessing globals that do not exist throws an error instead of giving a default value. Another very helpful feature is "parameter type constraints," which are a way of specifying valid types that function parameters may accept. These checks are still performed at runtime unlike in static languages, but their concise syntax and negligible performance impact make them much more attractive and easy-to-use than similar solutions in other dynamic languages. They can help greatly in catching bugs that would cause functions to malfunction or corrupt data structures if called with unexpected parameter types. A small example is given below.

Example code

The following example code is for MiniD 2.
Here is the Hello world program in MiniD.

module test
writeln

Every MiniD source file must begin with a module declaration. For simplicity, the module declaration has been omitted in the rest of the examples.

class Test
local t = Test
writeln

This example shows a simple class with two fields, x and y, which are initialized to 0 by default. The class's constructor, declared with the 'this' keyword, takes two parameters and assigns them to the instance's fields. The syntax ":x" is shorthand for "this.x", where "this" is the object upon which a method was called. Just like in Lua or Python, members of "this" must be accessed explicitly.
The class has one method, 'toString', which is called automatically when the object needs to be converted to a string. The somewhat unusual syntax used here is inspired by many functional languages and is shorthand for the following:

function toString

Finally, the class is instantiated by calling it like a function, similarly to Python or Squirrel. When the instance is printed out using 'writeln', the 'toString' method is called, and so this program outputs "".

local a = array.range
local b = a.map
writeln

This example demonstrates some of MiniD's array manipulation abilities. Unlike Lua, MiniD has a separate array type. In this example, an array is created that holds the values 1 through 10 using the 'array.range' function. Then the 'map' method of arrays is used on 'a', and it takes a function literal which returns the square of its parameter. This literal syntax is again inspired by functional languages and is shorthand for the following:

local b = a.map

When 'b' is printed, it shows the first ten squares, that is "".
writeln
This shows a shorter way of achieving the same result, using MiniD's list comprehensions. The syntax is very close to Python's.

local a =
local t =
local s = "hello"
foreach
writefln
writeln
foreach
writefln
writeln
foreach
writefln

This example shows the 'foreach' loop, which can be used to iterate over arrays, tables, and strings as shown here, as well as other types.

function countDown = coroutine function
foreach
writefln

This example shows the use of the 'foreach' loop to iterate over a coroutine. In this way, coroutines can be used as generators.

function first = x
writeln // prints 1
writeln // prints h
writeln // error, invalid parameter type 'int'

This shows a simple use of parameter type constraints, a way of putting runtime checks on parameters to restrict their allowable types. The 'first' function allows only arrays and strings for its parameter 'x'. The first two print statements work fine, but the third throws an error since integers are not an allowable type for 'x'.