Aikido (programming language)
From Wikipedia, the free encyclopedia
Aikido | |
---|---|
Paradigm | object oriented, multithreading, scripting language, imperative |
Appeared in | 2003 |
Designed by | David Allison, Sun Microsystems |
Typing discipline | Partially dynamic (duck), weak |
Major implementations | Aikido |
Influenced by | C, C++, Java, JavaScript, Perl, BASIC, Verilog, Ada 83, Pascal |
Aikido is a relatively new programming language that can be used for rapid scripting, prototyping and general programming tasks. It was developed in Sun Microsystems Laboratories by David Allison and released as open source in September 2003. It is a dynamically typed, object oriented language with built-in multithreading. In some respects it is similar in functionality to Python, Perl, JavaScript and Java. Syntactically it is very similar to C++ and Java.
Full documentation for the Aikido language is available in the Programmers reference manual
Contents |
[edit] Heritage
The name Aikido refers to the Japanese martial art of the same name and was chosen because the language, like the martial art is derived from many other parts, taking the most desirable aspects of each. The original name for the Aikido language was Darwin but this was such a common name that it was unavailable for use by Sun.
The original use for Aikido was as the control language for an assembler for an internal experimental simulation project within Sun Microsystems Laboratories. The language run-time system still maintains the hooks necessary to make it into a control language.
[edit] Characteristics
Modern scripting languages are used for many tasks ranging from control of the computer operating system to general application programming. The ever increasing speed of computers has made it much more feasible to write programs using an interpreted language rather than the traditional compiled languages.
Interpreted languages typically run slower than their compiled cousins, but provide much more flexibility for the programmer, resulting in a much compressed development time.
Aikido is an interpreted language that retains most of the syntactic characteristics of C++. Most of the elements of the language will be familiar to anyone who understands C++ (or Java, since it is also derived somewhat from C++).
[edit] Design Goals
The Aikido language was designed with a number of goals in mind.
- Familiarity. Anyone who is familiar with programming in C++ or similar languages should recognize the constructs used in Aikido.
- Evolution. There are many desirable features in the multitude of programming languages in existence. Aikido selects the most desirable of these from languages ranging from BASIC to Verilog.
- Speed. Being an interpreted language, Aikido cannot compete with compiled languages in terms of speed. Aikido's speed goal is to be fast enough to be useful in its own right without trying to attain compiled speeds.
- Readability. A program written in Aikido should be readable by a person who did not write it.
[edit] Hello world
The Hello world program in Aikido is very simple:
println ("Hello world")
This is executed by the following command in a Unix like shell (assuming that it is saved in a file called hello.aikido
$ aikido hello.aikido
The result is
$ aikido hello.aikido Hello world $
[edit] Implementations
Aikido is supplied primarily as source code. It is written entirely in C++ and is available for Linux, Mac OS X and Solaris. There is currently no Windows port available.
[edit] Language Features
[edit] Novel features
Aikido contains a number of novel language features:
- Partially dynamically typed variables
- Variables are assigned a value of any type when they are created and cannot change type after that.
var x = 1 var pi = 3.14159265
x = pi // error, cannot change type once defined
This feature reduces programming errors by not permitting arbitrary type changes at runtime. A variable may also be declared as generic thus allowing its type to change.
- Block derivation
- In most object oriented languages, a class may be derived from another class forming a class hierarchy. In Aikido, this concept is available for any block. This includes functions, threads, monitors and enumerations.
- Statement macros
- A macro is a textually-replaced name that may be used at the statement level of a program
- Stream operator
- The built-in stream operator (
->
) may be used to stream data to and from devices and program elements.
- Raw native functions
- Aikido can invoke code that resides in an external library directly without requiring complex mapping and conversion. This is subject to certain rules.
- Switch statement comparison operators
- The case limbs of a switch statement can contain comparison operators that allow for comparisons other than the normal equality comparison. The operators can be one of ==, !=, <, <=, >, >=, in.
- Smart statement boundary detection
- The use of a semicolon (
;
) character is optional in Aikido. It may be used if desired to separate statements but the language compiler has a special algorithm that is used to detect the end of statements unambiguously. This means that you rarely need to insert a semicolon at the end of a line, unlike most other languages.
[edit] Familiar features
In common with many other languages, Aikido provides the following program constructs:
- Variables and constants
- A variable is a named program storage location. Variables must be assigned a value when they are declared. Variables and constants are held in scopes and do not interfere with enclosing or non-intersecting scopes. Variables and constants must be declared before use
A variable may also be declared as fully dynamic using the generic keyword. In this case no value need be assigned to it at declaration time
- Type casts
- A value can be converted to another type using a cast operation. The syntax is similar the that in C++ but simplified. Casts are always performed at runtime and a specific cast operator may be defined for a class.
- Functions
- A function is a program segment that is called and performs some operations before (possibly) returning a value. If no value is explicitly returned, the value none is returned.
A function can be declared as returning a particular type. The actual value returned is cast to the return type at runtime.
- Classes
- A class is an object oriented type. They may be derived from other classes to form a class hierarchy. They provide a set of functions and operators that manipulate instances of the class. The class may take arguments and its constructor is the body of the block.
class Planet (name) extends Object (name) { public function draw (screen) { // draw the planet } }
var earth = new Planet ("earth") earth.draw (screen3)
- Access control
- Like C++ and Java, Aikido controls access to all members of blocks. By default membership is private but may be made public or protected using keywords.
- Interfaces
- Similar to Java, Aikido provides an interface concept to constitute a contract to provide certain functions in the class. A class may implement one or more interfaces
- Closures and coroutines
- A closure in Aikido is an object that contains everything that is needed to invoke a function from any point in the program. This includes the function's static link chain. A closure is created by passing a function name as an argument or by returning it from a function. A coroutine is an extension of a closure that also includes the current state of a function (all data, program counter and registers). A coroutine yields to its caller using the yield keyword. It can be resumed inside a foreach statement or by calling the next() function on the closure.
- Polymorphic functions
- Similar to Java, all public functions in a block are be overridden by a block derived from it. This is known as virtual functions in C++.
- Static members
- Block members may be declared static meaning that their memory resides in the outer program level. This allows them to maintain their value.
- Parameters
- Block (function, class, etc.) parameters have the following facilities:
- Access control
- Type coercion
- Pass by reference using the var keyword
- Variable parameter list using the ellipsis notation
- Default values
The following example shows the various parameter mechanisms
function foo (a, public b, var c, d:int, e = "hello", ...) { // a is private and passed by value // b is public and passed by value // c is passed by reference // d is cast to int on call // e is passed by value and has a default value // more parameters available in args variable }
The use of access control for functions is only useful in the case of function derivation.
- Threads
- A thread is a thread of control in the program and executes independently of other threads.
- Packages
- A package is a collection of program constructs collected in one place for use by another program. They may be used to provide libraries.
- Monitors
- A monitor is a thread synchronization object that controls access to memory and also provides a signaling facility
- Strings
- A string is a sequence of characters. Many operations are available for them including insertion, searching, deletion, shifting, etc.
- Vectors
- A vector is a sequence values of any type. They may be manipulated and extended by built-in operations
- Maps
- A map is an associative container that maps one value to another.
- Iteration
- The iteration constructs of Aikido are similar to those in other languages from the C family (while, for and do..while loops), but also includes a high-level iteration construct foreach.
- Selection
- The selection facilities include if and switch statements.
- Enumeration
- Aikido provides an enumeration ability that is similar to that provided in Pascal.
- Operator Overloading
- The C++ style of operator overloading is provided by Aikido. This is also used to provide type conversions and iterators.
- Lexical Scoping
- Similar to languages such as Pascal and Ada, Aikido allows nested definitions for blocks. In this way, a function (or indeed, any block) can be defined within another function to an arbitrary depth.
- Garbage Collection
- Aikido uses reference counting garbage collection. It keeps track of all references to objects and deletes the memory when there is nothing referring to them. In addition, a delete operator is available to allow removal of circular references.
In addition, raw memory may be allocated for use in the program using the familiar malloc function. This memory is garbage collected when there are no references remaining. Access to the contents of the memory is performed using the peek and poke facilities, borrowed from the venerable BASIC language.
- Exceptions
- Exceptions are very similar to C++ in that you throw a value that is caught using a catch clause. The major difference is that there may only be one catch clause for a try block. Any value may be thrown and caught.
[edit] Native functions
An interpreted programming language cannot execute a program independently from the operating system upon which it is running. It must make use of the operating system facilities to perform certain tasks such as input/output, memory allocation, etc. Aikido provides a relatively easy way to invoke code that resides outside the interpreter in an external library. This facility is normally referred to as native function access.
[edit] Uses
Along with general scripting and programming, Aikido can be used as a control language for a larger application. One such application is Command Line Interpreter where it can be used to provide a built-in scripting ability.
Whenever the Aikido interpreter comes across a section of code that it does not understand, it has the ability to pass this off to another program known as a worker. This worker program can then use this unrecognized text as a command.
[edit] Comparison with other languages
Aikido is in part derived from the syntax and semantics of other programming languages.
[edit] C++
Aikido's syntactic constructs are mostly derived from the C++ programming language. The expression syntax is almost exactly like C++ with some extensions for higher level constructs. The object orientation is similar to C++ except that multiple inheritance is not available.
[edit] Java
Java is also a language that is similar in construct to C++. Aikido takes a number of Java's constructs in favor of similar constructs in C++. For example, the object oriented class structure is Java-like in that is provides single inheritance, uses extends for derivation and provides interfaces.
[edit] Pascal
Niklaus Wirth's Pascal language provides a number of features that Aikido has borrowed. In particular, the lexical structure of an Aikido program is similar to that in Pascal. This is known as lexical scoping and allows a nested block to access the variables in an enclosing block. Some syntactic elements are also derived from Pascal. For example, the use of the keyword "var" to denote call by reference in function formal argument lists.
[edit] Python
Python and Aikido are quite similar in some respects, but vastly different in others. Syntactically, Aikido is a lot different from Python, the former being derived from the C family of languages, and the latter having a unique syntactic style. Despite their differences, Aikido and Python share a similar goal and runtime ability. The runtime libraries for both languages are very similar, with Python having a much richer set of functions.
[edit] JavaScript
Aikido is very similar to the JavaScript language. Syntactically it is almost identical, but one major difference is the object orientation features. JavaScript uses a prototype style of inheritance where Aikido uses a traditional class hierarchy.
[edit] Runtime library
Aikido's runtime library is relatively small in comparison to other languages. A lot of the features normally found in runtime libraries in other language systems are built in to the Aikido interpreter. For example, Aikido provides extensive string manipulation operations in the interpreter itself rather than relying on calls to an external library.
Most of the library functions and classes are used to provide operating system access facilities. For example, runtime library functions are available to access the operating system shell.
The runtime library is accessed in an Aikido program by importing one of the few files contained in the Aikido package. Once imported, the functions and classes of that section of the runtime library can be used in the program.
[edit] Patents
Many of the features and facilities in Aikido are subject to a number of US patents: