MiniD

Last updated
MiniD
Minidlogo2.png
Paradigm Multi-paradigm: object-oriented, Imperative
Designed by Jarrett Billingsley
Developer Jarrett Billingsley
First appeared2006;14 years ago (2006)
Stable release
2.0 / June 16, 2009;11 years ago (2009-06-16)
Typing discipline Dynamic
OS Cross-platform
License zlib/libpng
Filename extensions .md
Website www.dsource.org/projects/minid
Influenced by
D, Lua, Squirrel, Python, Io, ECMAScript
Influenced
Croc [1]

The MiniD (has been renamed Croc) 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.

Contents

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 [2] and used as the base for new language called Croc by the same author. [1]

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 (as in Lua). 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. (Note that due to technical limitations, some keywords are not highlighted here, as Wikipedia does not have a source highlighter for MiniD.)

Here is the Hello world program in MiniD.

moduletestwriteln("Hello, world!")

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

classTest{x=0y=0this(x,y){:x=x:y=y}functiontoString()=format("x = {} y = {}",:x,:y)}localt=Test(3,4)writeln(t)

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:

functiontoString(){returnformat("x = {} y = {}",:x,:y)}

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 "x = 3 y = 4".

locala=array.range(1,11)localb=a.map(\x->x*x)writeln(b)

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 (such as Haskell) and is shorthand for the following:

localb=a.map(function(x){returnx*x})

When 'b' is printed, it shows the first ten squares, that is "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]".

writeln([x * x for x in 1 .. 11])

This shows a shorter way of achieving the same result, using MiniD's list comprehensions. The syntax is very close to Python's.

locala=[1,2,3,4,5]localt={x=5,y=10}locals="hello"foreach(i,v;a)writefln("a[{}] = {}",i,v)writeln()foreach(i,v;t)writefln("t.{} = {}",i,v)writeln()foreach(i,v;s)writefln("s[{}] = {}",i,v)

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.

functioncountDown(val:int)=coroutinefunction(){while(val>0){yield(null,val)// this is like yielding an index and a valueval--}}foreach(v;countDown(5))writefln(v)

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

functionfirst(x:array|string)=x[0]writeln(first([1,2,3]))// prints 1writeln(first("hello"))// prints hwriteln(first(45))// 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'.

Related Research Articles

Icon is a very high-level programming language featuring goal-directed execution and many facilities for managing strings and textual patterns. It is related to SNOBOL and SL5, string processing languages. Icon is not object-oriented, but an object-oriented extension called Idol was developed in 1996 which eventually became Unicon.

Lua (programming language) Lightweight programming language

Lua is a lightweight, high-level, multi-paradigm programming language designed primarily for embedded use in applications. Lua is cross-platform, since the interpreter of compiled bytecode is written in ANSI C, and Lua has a relatively simple C API to embed it into applications.

Generic programming is a style of computer programming in which algorithms are written in terms of types to-be-specified-later that are then instantiated when needed for specific types provided as parameters. This approach, pioneered by the ML programming language in 1973, permits writing common functions or types that differ only in the set of types on which they operate when used, thus reducing duplication. Such software entities are known as generics in Python, Ada, C#, Delphi, Eiffel, F#, Java, Nim, Rust, Swift, TypeScript and Visual Basic .NET. They are known as parametric polymorphism in ML, Scala, Julia, and Haskell ; templates in C++ and D; and parameterized types in the influential 1994 book Design Patterns.

D (programming language) Multi-paradigm system programming language

D, also known as Dlang, is a multi-paradigm system programming language created by Walter Bright at Digital Mars and released in 2001. Andrei Alexandrescu joined the design and development effort in 2007. Though it originated as a re-engineering of C++, D is a distinct language. It has redesigned some core C++ features, while also sharing characteristics of other languages, notably Java, Python, Ruby, C#, and Eiffel.

In mathematics and computer science, a higher-order function is a function that does at least one of the following:

Io is a pure object-oriented programming language inspired by Smalltalk, Self, Lua, Lisp, Act1, and NewtonScript. Io has a prototype-based object model similar to the ones in Self and NewtonScript, eliminating the distinction between instance and class. Like Smalltalk, everything is an object and it uses dynamic typing. Like Lisp, programs are just data trees. Io uses actors for concurrency.

The syntax of the C programming language is the set of rules governing writing of software in the C language. It is designed to allow for programs that are extremely terse, have a close relationship with the resulting object code, and yet provide relatively high-level data abstraction. C was the first widely successful high-level language for portable operating-system development.

In computer science, a generator is a routine that can be used to control the iteration behaviour of a loop. All generators are also iterators. A generator is very similar to a function that returns an array, in that a generator has parameters, can be called, and generates a sequence of values. However, instead of building an array containing all the values and returning them all at once, a generator yields the values one at a time, which requires less memory and allows the caller to get started processing the first few values immediately. In short, a generator looks like a function but behaves like an iterator.

Foreach loop control flow statement

Foreach loop is a control flow statement for traversing items in a collection. Foreach is usually used in place of a standard for loop statement. Unlike other for loop constructs, however, foreach loops usually maintain no explicit counter: they essentially say "do this to everything in this set", rather than "do this x times". This avoids potential off-by-one errors and makes code simpler to read. In object-oriented languages an iterator, even if implicit, is often used as the means of traversal.

In some programming languages, eval is a function which evaluates a string as though it were an expression and returns a result; in others, it executes multiple lines of code as though they had been included instead of the line including the eval. The input to eval is not necessarily a string; it may be structured representation of code, such as an abstract syntax tree, or of special type such as code. The analog for a statement is exec, which executes a string as if it were a statement; in some languages, such as Python, both are present, while in other languages only one of either eval or exec is.

IP Pascal is an implementation of the Pascal programming language using the IP portability platform, a multiple machine, operating system and language implementation system.

Squirrel is a high level imperative, object-oriented programming language, designed to be a lightweight scripting language that fits in the size, memory bandwidth, and real-time requirements of applications like video games and embedded systems.

Scala (programming language) General-purpose programming language

Scala is a general-purpose programming language providing support for both object-oriented programming and functional programming. The language has a strong static type system. Designed to be concise, many of Scala's design decisions are aimed to address criticisms of Java.

Haxe

Haxe is an open source high-level cross-platform programming language and compiler that can produce applications and source code, for many different computing platforms from one code-base. It is free and open-source software, released under the MIT License. The compiler, written in OCaml, is released under the GNU General Public License (GPL) version 2.

In computer programming, an anonymous function is a function definition that is not bound to an identifier. Anonymous functions are often arguments being passed to higher-order functions, or used for constructing the result of a higher-order function that needs to return a function. If the function is only used once, or a limited number of times, an anonymous function may be syntactically lighter than using a named function. Anonymous functions are ubiquitous in functional programming languages and other languages with first-class functions, where they fulfil the same role for the function type as literals do for other data types.

The structure of the Perl programming language encompasses both the syntactical rules of the language and the general ways in which programs are organized. Perl's design philosophy is expressed in the commonly cited motto "there's more than one way to do it". As a multi-paradigm, dynamically typed language, Perl allows a great degree of flexibility in program design. Perl also encourages modularization; this has been attributed to the component-based design structure of its Unix roots, and is responsible for the size of the CPAN archive, a community-maintained repository of more than 100,000 modules.

Nemerle is a general-purpose, high-level, statically typed programming language designed for platforms using the Common Language Infrastructure (.NET/Mono). It offers functional, object-oriented and imperative features. It has a simple C#-like syntax and a powerful metaprogramming system. In June 2012, the core developers of Nemerle were hired by the Czech software development company JetBrains. The team is focusing on developing Nitra, a framework to implement extant and new programming languages. This framework will likely be used to create future versions of Nemerle.

Kotlin is a cross-platform, statically typed, general-purpose programming language with type inference. Kotlin is designed to interoperate fully with Java, and the JVM version of Kotlin's standard library depends on the Java Class Library, but type inference allows its syntax to be more concise. Kotlin mainly targets the JVM, but also compiles to JavaScript or native code, e.g. for native iOS apps sharing business logic with Android apps. Language development costs are borne by JetBrains, while the Kotlin Foundation protects the Kotlin trademark.

Torch (machine learning)

Torch is an open-source machine learning library, a scientific computing framework, and a script language based on the Lua programming language. It provides a wide range of algorithms for deep learning, and uses the scripting language LuaJIT, and an underlying C implementation. As of 2018, Torch is no longer in active development. However PyTorch, which is based on the Torch library, is actively developed as of June 2020.

Modern Pascal is a closed source, cross-platform, interpreter, compiler and runtime environment for command line, server-side and networking applications. Modern Pascal applications are written in Pascal/Object Pascal, and can be run within the Modern Pascal runtime on Microsoft Windows, Linux, OS X, FreeBSD, Solaris and DOS/32 operating systems. Its work is hosted and supported by the 3F, LLC and partner MP Solutions, LLC.

References

  1. 1 2 "The Croc Programming Language". croc-lang.org. Retrieved 1 October 2011.
  2. "BIG NEWS: Name change, possible port, and moving!". dsource.org. 18 June 2011. Retrieved 1 October 2011.