I want to add a simple recursive function as a cell value. Let’s say
fib = function(n) {
if (n == 0) return 0;
if (n == 1) return 1;
return fib(n - 1) + fib(n - 2);
}
– but Observable complains about circular definition.
I understand that Observable needs to evaluate fib in a reactive way, and it cannot resolve the circular definition. I could work around that by specifiying:
fib = function(n) {
function _fib(n) {
if (n == 0) return 0;
if (n == 1) return 1;
return _fib(n - 1) + _fib(n - 2);
}
return _fib(n)
}
… but I would like to avoid that for didactic purposes (this is for a tutorial directed towards newcomers).
I briefly looked into the mutable keyword, but I feel like I would need the opposite, like an immutable keyword that breaks reactive evaluation.
Any suggestion for how to get this to work without introducing too much semantic noise that unnecessarily confuses newcomers/students?