Neko (programming language)
Encyclopedia
Neko is a high-level dynamically typed programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

 developed by Nicolas Cannasse as part of R&D efforts at Motion-Twin.

Concept

Neko has a compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...

 and a virtual machine
Virtual machine
A virtual machine is a "completely isolated guest operating system installation within a normal host operating system". Modern virtual machines are implemented with either software emulation or hardware virtualization or both together.-VM Definitions:A virtual machine is a software...

 with garbage collection
Garbage collection (computer science)
In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program...

. The compiler converts a source .neko file into a bytecode .n file that can be executed with the virtual machine. Since Neko is dynamically typed with no fixed classes, a developer only has to find the proper runtime mapping (as opposed to type mapping) so that code executes correctly. As the Neko FAQ
FAQ
Frequently asked questions are listed questions and answers, all supposed to be commonly asked in some context, and pertaining to a particular topic. "FAQ" is usually pronounced as an initialism rather than an acronym, but an acronym form does exist. Since the acronym FAQ originated in textual...

 puts it: "...it is easier to write a new or existing language on the NekoVM than it is for the CLR / JVM, since you don’t have to deal with a highlevel type system. Also, this means that languages can interoperate more easily since they only need to share the same data structures and not always the same types."

Neko requires compilation before execution, like other scripting languages such as Groovy. Since Neko doesn't need to be interpreted at runtime, it executes faster. The haXe
HaXe
haXe is a versatile open-source high-level multiplatform programming language described on its website as a "universal language".It can produce:* Flash applications and games* Multi-platform client-side web applications* Apache CGI web applications...

 programming language compiles to Neko code, among other targets.

Type conversions


$int("67.87"); // Converts string "67.87" to integer 67
$float(12345); // Converts integer 12345 to float 12345.0000
$string($array(1,2,3)); // Converts array [1,2,3] to string "[1,2,3]"

Objects


o = $new(null); // new empty object
o2 = $new(o); // makes a copy of o
o2 = $new(33); // if parameter is not an object, throw an exception
o.field = value; //sets field to value
o.field; // returns "field" value of object o

Methods


foo = function {
$print(this.x);
}
o = $new(null);
o.x = 3;
o.bar = function {
foo;
};
o.bar; // prints 3

Function scope


var x = 3;
f = function {
$print(x);
}
x = 4;
f; // print 3

Prototypes


var proto = $new(null);
proto.foo = function {
$print(this.msg) }

var o = $new(null);
o.msg = "hello";
$objsetproto(o,proto);
o.foo; // print "hello"

$objsetproto(o,null); // remove proto
o.foo; // exception

Web functionality

Neko includes a mod_neko module for the Apache
Apache HTTP Server
The Apache HTTP Server, commonly referred to as Apache , is web server software notable for playing a key role in the initial growth of the World Wide Web. In 2009 it became the first web server software to surpass the 100 million website milestone...

server. As such, it can process user input using GET and POST requests:

get_params = $loader.loadprim("mod_neko@get_params",0);
$print("PARAMS = "+get_params);

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK