memoize -- AAs don't work for ubyte[4] keys

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Jan 4 06:07:50 PST 2011


On 1/4/11 6:32 AM, spir wrote:
> On Mon, 03 Jan 2011 23:27:22 -0600
> Andrei Alexandrescu<SeeWebsiteForEmail at erdani.org>  wrote:
>
>> Nevertheless, I found two issues: one, ParameterTypeTuple doesn't work
>> for overloaded functions, and associative arrays don't work for ubyte[4]
>> keys... still a ways to go.
>
> Could you or someone else expand on this?
>
> Denis
> -- -- -- -- -- -- --
> vit esse estrany ☣
>
> spir.wikidot.com
>

An example in Higher Order Perl is memoizing a RGB to CMYK function:

ubyte[4] rgb2cmyk(ubyte[3] rgb)
{
     ubyte[4] result = void;
     result[0] = cast(ubyte)(255 - rgb[0]);
     result[1] = cast(ubyte)(255 - rgb[1]);
     result[2] = cast(ubyte)(255 - rgb[2]);
     result[3] = min(result[0], result[1], result[2]);
     result[0] -= result[3];
     result[1] -= result[3];
     result[2] -= result[3];
     return result;
}

Trying to memoize this yields a range error at runtime.


Andrei


More information about the Digitalmars-d mailing list