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:

    My God! The English language is a form of communication! Conversation isn’t just crossfire where you shoot and get shot at! Where you’ve got to duck for your life and aim to kill! Words aren’t only bombs and bullets—no, they’re little gifts, containing meanings!
    Philip Roth (b. 1933)

    A mind enclosed in language is in prison.
    Simone Weil (1909–1943)

    These are our grievances which we have thus laid before his majesty with that freedom of language and sentiment which becomes a free people, claiming their rights as derived from the laws of nature, and not as the gift of their chief magistrate.
    Thomas Jefferson (1743–1826)