Ha Xe - Language

Language

The Haxe language is similar to ECMAScript, although almost no ECMAScript code will run on Haxe without modifications. Unlike ECMAScript, Haxe is a compiled language. It is a general-purpose language with object-oriented programming, exceptions, and type inference with class parameters. Generic classes, reflectivity, iterators, and functional programming are built-in functionality of the language and libraries. Unusual among programming languages, Haxe contains a type system which is both strong and dynamic. The compiler will check types implicitly and give compile-time errors, but it also enables the programmer to bypass type-checking and rely on the target platform's dynamic type-handling.

Since Haxe had its origins in AS3, all of the existing Flash API can be used, although Haxe requires better-formed code and programming standards than Adobe compilers (for example, with regard to scoping and data typing).

Function parameters can be defined very precisely in Haxe:

function multipleparams (threedimensionalarray : Array>>, stringval : String, boolval : Bool) { } // optional int value returning an int function optionalargument ( ?i : Int ) : Int { return 0; } // call a function with no parameters function functionasparameter ( f : Void -> Void ) { f; } // call a function that returns an int, with an int parameter function anotherfunctionparm ( f : Int -> Int ) { var result = f(1); } // function which takes any kind of type and returns it function icoulddoanything (d : Dynamic) : Dynamic { return d; }

Enumerated types are a key feature of the language; they can have parameters of their own and be recursive. They are similar to algebraic data types in languages like ML or Haskell. Enums in Haxe are not simply indexed "magic-number" values as in most languages, but are more abstract: they contain no inherent value, but can be instanced into variables as in this example:

enum Color { red; green; blue; rgb: ( r : Int, g : Int, b : Int ); } class Colors { static function toInt ( c : Color ) : Int { return switch ( c ) { case red: 0xFF0000; case green: 0x00FF00; case blue: 0x0000FF; case rgb(r, g, b): (r << 16) | (g << 8) | b; } } static function validCalls { var redint = toInt(Color.red); var rgbint = toInt(Color.rgb(100,100,100)); } }

This example draws a red square using a Flash MovieClip object, and utilizes the "using" keyword.

using Colors; class Test { static function main { var mc: flash.display.MovieClip = flash.Lib.current; mc.graphics.beginFill(red.toInt); mc.graphics.moveTo(50,50); mc.graphics.lineTo(100,50); mc.graphics.lineTo(100,100); mc.graphics.lineTo(50,100); mc.graphics.endFill; } }

Read more about this topic:  Ha Xe

Famous quotes containing the word language:

    When a language creates—as it does—a community within the present, it does so only by courtesy of a community between the present and the past.
    Christopher Ricks (b. 1933)

    It is difficult for a woman to define her feelings in language which is chiefly made by men to express theirs.
    Thomas Hardy (1840–1928)

    For all symbols are fluxional; all language is vehicular and transitive, and is good, as ferries and horses are, for conveyance, not as farms and houses are, for homestead.
    Ralph Waldo Emerson (1803–1882)