25 lines
760 B
Plaintext
25 lines
760 B
Plaintext
* A function which accepts a number N and returns the Nth fibonacci number
|
|
{
|
|
* We are passing a tuple of inputs into a graph here, such that the graph is
|
|
* evaluated as an anonymous function. That anonymous function uses !recur
|
|
* internally to compute the result.
|
|
!out = {
|
|
|
|
* A little helper function.
|
|
decr = { !out = !add < (!in, -1) };
|
|
|
|
* Deconstruct the input tuple into its individual elements, for clarity.
|
|
* There will be a more ergonomic way of doing this one day.
|
|
n = !tupEl < (!in, 0);
|
|
a = !tupEl < (!in, 1);
|
|
b = !tupEl < (!in, 2);
|
|
|
|
!out = !if < (
|
|
!isZero < n,
|
|
a,
|
|
!recur < ( decr<n, b, !add<(a,b) ),
|
|
);
|
|
|
|
} < (!in, 0, 1);
|
|
}
|