ZEL and deterministic functions

09:39AM Feb 23, 2010 in category Java by Zoltan Farkas

A few days of bad wether and the ZEL language gets some significant enhancements:

Deterministic functions:

Q: What is a deterministic function?

A: A funtion that always returns the same value, for the same parameters.

How do we define a deterministic function:

fib= lambda deterministic (x) { fib( x-1) + fib( x-2); };

fib(0)=0; fib(1)=1;

Now as you can see this allows to a "clearer" and potentially better performing implementation when we compare with the traditional implementation:

fib= lambda(x){ return (x == 0) ? 0 : (x == 1) ? 1 : fib( x-1) + fib( x-2); };

When we assign a value to a function that value is added to that functions result cache(permanent area). When a result of a deterministic function is computed it is also automatically stored in the result cache (transient area). The function result cache is a new feature of the ZEL virtual machine, only deterministic function results are stored in this cache. The cache features a permanent and transient zone. The transient zone stored values can be garbage collected at any time (weak references).

I have uploaded the implementation to sourceforge: http://zel.sf.net and kenai: http://kenai.com/projects/zel

cheers

Comments[0]

Comments:

Post a Comment:
Comments are closed for this entry.