Did you know?

General


using and callback


The callback statement allows currying, thus enabling the use of multiple argument functions in places where single argument functions are expected, e.g.
var l:List<Float> = Lambda.map([1, 2, 3], callback(Math.pow, 2));
The signature of Math.pow is "Float -> Float -> Float", which is not compatible with Lambda.map requiring a "Float -> Float" function here. However, with the callback statement the signature might be rewritten as "2 -> Float -> Float", i.e. a function with 2 as first argument that takes a Float and returns a Float. This is compatible with Lambda.map, which now calls Math.pow(2,1), Math.pow(2,2) and Math.pow(2,3).

The using statement also applies the callback mechanism:

using Math;
var l:List<Float> = Lambda.map([1, 2, 3], 2.pow);
The 2.pow is translated to exactly the above callback example. Finally, true functional beauty is achieved by another using statement:
using Math;
using Lambda;
var l:List<Float> = [1, 2, 3].map(2.pow);

inlining, overriding and implementing


You cannot inline overriding methods because they are resolved at runtime while inlining is done at compile time. You also cannot specify "inline" in interfaces. You can, however, implement an interface and declare the implementation as "inline":
interface OpCode {
    public function execute(argument:Int):Int;
}
class ADC implements OpCode {
    public inline function execute(argument:Int):Int {
        return 0;
    }
}

This might be an alternative to using common base classes in cases where performance is important.

Flash


flash.Memory to ByteArray


The contents of the memory modified through the flash.Memory API can easily be passed to functions expecting a ByteArray:
bitmapData.setPixels(bitmapData.rect, flash.system.ApplicationDomain.currentDomain.domainMemory);

Containers


Arrays are slow, use them only if you need indexed access to your elements. Lists aren't any better because their implementation is based on Arrays. If you don't need indexed access, consider using haxe.FastList.

version #8349, modified 2010-03-24 10:41:49 by Simn