MiniD

MiniD
MiniD
Minidlogo2.png
Logo designed by Andrzej Rutkowski
Paradigm(s) Multi-paradigm: object-oriented, Imperative
Appeared in 2006
Designed by Jarrett Billingsley
Developer Jarrett Billingsley
Stable release 2.0 (June 16, 2009 (2009-06-16))
Typing discipline Dynamic
Influenced by D, Lua, Squirrel, Python, Io, ECMAScript
Influenced Croc[1]
OS Cross-platform
License zlib/libpng
Usual filename extensions .md
Website MiniD DSource Page

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.

Contents

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.

 module test
 writeln("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.

 class Test
 {
     x = 0
     y = 0
 
     this(x, y)
     {
         :x = x
         :y = y
     }
 
     function toString() = format("x = {} y = {}", :x, :y)
 }
 
 local t = 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:

 function toString()
 {
     return format("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".

 local a = array.range(1, 11)
 local b = 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:

 local b = a.map(function(x) { return x * 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.

 local a = [1, 2, 3, 4, 5]
 local t = { x = 5, y = 10 }
 local s = "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.

 function countDown(val: int) = coroutine function()
 {
     while(val > 0)
     {
         yield(null, val) // this is like yielding an index and a value
         val--
     }
 }
 
 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.

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

References

  1. ^ a b "The Croc Programming Language". croc-lang.org. http://www.croc-lang.org/. Retrieved 1 October 2011. 
  2. ^ "BIG NEWS: Name change, possible port, and moving!". dsource.org. 18 June 2011. http://www.dsource.org/forums/viewtopic.php?t=5958. Retrieved 1 October 2011. 

External links


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • MinID — is an electronic login system used to secure a range of internet services in the Norwegian public sector. The communication done with MinID is encrypted to secure information from unauthorized usage.[1] Everyone registered in the Norwegian… …   Wikipedia

  • Women in Pakistan — The status of women in Pakistan varies considerably across classes, regions, and the rural/urban divide due to uneven socioeconomic development and the impact of tribal, feudal, and capitalist social formations on women s lives. The Pakistani… …   Wikipedia

  • Amanullah Khan Jadoon — is a Pakistani politician served as the Federal Minister for Petroleum Natural Resources during 2002 to 2007 and political rival of Mehtab Ahmed Khan. [ [http://www.pakistan.gov.pk/ministries/ContentInfo.jsp?MinID=44 cPath=764 765 ContentID=4011… …   Wikipedia

  • Microsiervos (blog) — Microsiervos Información general URL http://www.microsiervos.com/ Comercial Sí Tipo de sitio Blog …   Wikipedia Español

  • Manṣūr, Abū Yūsuf Yaʿqūb al- — ▪ Almohad and Muʾminid ruler in full  Abū Yūsuf Yaʿqub Ibn ʿabd Al muʾmin Al manṣūr   born c. 1160 died Jan. 23, 1199, Marrakech, Mor.       third ruler of the Muʾminid dynasty of Spain and North Africa, who during his reign (1184–99) brought the …   Universalium

  • Coroutine — Coroutines are computer program components that generalize subroutines to allow multiple entry points for suspending and resuming execution at certain locations. Coroutines are well suited for implementing more familiar program components such as …   Wikipedia

  • D (programming language) — For other programming languages named D, see D (disambiguation)#Computing. D programming language Paradigm(s) multi paradigm: imperative, object oriented, functional, meta Appeared in 1999 (1999) Designed by …   Wikipedia

  • Zubaida Jalal Khan — (Urdu: زبيدہ جلال خان ) is a Pakistani politician. She served as Minister for Education, Women s development. She held the office of federal minister for Social Welfare and Special Education in the cabinet of Shaukat Aziz then the Prime Minister… …   Wikipedia

  • Ministry of Agriculture, Food and Rural Affairs (Ontario) — Ministry of Agriculture, Food and Rural Affairs Ministère de L Agriculture, de L Alimentation et des Affairs Rurales Government ministry overview Formed March 9, 1994 (1994 03 09) Preceding Government ministry Ministry of Agriculture and… …   Wikipedia

  • National symbols of Pakistan — Pakistan has several official national symbols including a historic document, a flag, an emblem, an anthem, a memorial tower as well as several national heroes. The symbols were adopted at various stages in the existence of Pakistan and there are …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”