Iteractive Fibonacci example

11 views
Skip to first unread message

Dale Schumacher

unread,
May 30, 2026, 10:22:06 AM (7 days ago) May 30
to fr...@googlegroups.com
During yesterday's friam call we explored iterative calculation of Fibonacci numbers as a demonstration of techniques for implementing functional closure activations and parallel list processing using pure actors in uFork assembly language. For future reference, the code for this example has been published at https://ufork.org/playground/?src=../debugger/examples/fib_iter.asm

Douglas Crockford

unread,
May 31, 2026, 8:56:00 AM (6 days ago) May 31
to friam


This is how I did it in The Good Parts:

 var memoizer = function (memo, formula) {
    var recur = function (n) {
        var result = memo[n];
        if (typeof result !== 'number') {
            result = formula(recur, n);
            memo[n] = result;
        }
        return result;
    };
    return recur;
};
var fibonacci = memoizer([0, 1], function (recur, n) {
    return recur(n - 1) + recur(n - 2);
});

Dale Schumacher

unread,
May 31, 2026, 11:04:12 AM (6 days ago) May 31
to fr...@googlegroups.com
This is an elegant example using higher-order functional closures and shared mutable state. However, the memory-safe assembly language of uFork has neither of these mechanisms, so compiler-writers will need to build semantic equivalents using pure share-nothing actors and immutable message data. We look forward to illustrating this (eventually) with a compiler for Misty.

--
You received this message because you are subscribed to the Google Groups "friam" group.
To unsubscribe from this group and stop receiving emails from it, send an email to friam+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/friam/67d5c48b-27c9-4de7-baf3-45de2024b413n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages