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:

    The writer’s language is to some degree the product of his own action; he is both the historian and the agent of his own language.
    Paul De Man (1919–1983)

    Experiment is necessary in establishing an academy, but certain principles must apply to this business of art as to any other business which affects the artis tic sense of the community. Great art speaks a language which every intelligent person can understand. The people who call themselves modernists today speak a different language.
    Robert Menzies (1894–1978)

    Poetry is the universal language which the heart holds with nature and itself. He who has a contempt for poetry, cannot have much respect for himself, or for anything else.
    William Hazlitt (1778–1830)