Getting Started

As with any language, the very first thing we have to do is write a "Hello world" program. Go on, you have to.

Create a file named "test.md" and into it insert the following code:

module test;
writeln("Hello world!");

Once you've done that, grab MDCL, the standalone MiniD interpreter (it works on Windows and through Wine on Linux), and run it like so:

mdcl test

At which point you'll get the standard first-thing-you-do-in-any-programming-language greeting.

How about a program that asks the user for a number and prints the square of it?

module test;

function square(num)
{
	return num * num;
}

write("Enter a number: ");
local num = toInt(readln());
writefln("The square of {} is {}.", num, square(num));

Doesn't look too scary, no? Running it with MDCL will give you a prompt, at which you enter a number, and you'll get an answer.

Let's pick these examples apart.

Modules

Each MiniD script file (which have the file extension ".md") corresponds to a module, the top-level organizational entity in the language. You can have any number of modules in arbitrary hierarchies. Modules always begin with a module declaration, which is the "module test;" line at the beginning of both the examples in the last section. This name, similarly to D, can have multiple parts separated by periods, such as "foo.bar.baz". The name of the module in the module declaration corresponds to its path and filename on disk. A module named "test" will be in the file "test.md"; "foo.bar.baz" will be "foo/bar/baz.md". MDCL understands both pathnames and module names and will try to figure out what you want to load based on the name that you give it. With the above examples, you could use "mdcl test" or "mdcl test.md", or even "minidc test.md" (to compile the module to a binary file) and then "mdcl test.mdm" -- all of them will yield the same result.

A module is actually a big function. Everything after the module declaration is treated as the body of the function. This "module function" can take parameters and give results, though that's usually not the normal case.

When you run MDCL in interactive mode, though, you're not declaring a module. Each line you type in is kind of like the body of a module: a nameless function. However each line also shares a single global variable space.

Oof, I don't know if I want to go much further given the changes MiniD2 is going to bring..