diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-12-04 11:04:16 +0200 | 
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-12-04 11:04:16 +0200 | 
| commit | 5d4b4ef80d8dc427b0e2803d50e439f76f06e17a (patch) | |
| tree | a5869136c1e5e869d8e232927e06f27422f31234 /examples | |
| parent | 2253da61e9b3dd5408bed182ea08e5270156c17e (diff) | |
| download | fwd-5d4b4ef80d8dc427b0e2803d50e439f76f06e17a.tar.gz fwd-5d4b4ef80d8dc427b0e2803d50e439f76f06e17a.zip  | |
implement expression handling further
+ Add some notes about returning functions that I started thinking about
  as a result of the fib example
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/fib.fwd | 23 | 
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/fib.fwd b/examples/fib.fwd new file mode 100644 index 0000000..8b0e055 --- /dev/null +++ b/examples/fib.fwd @@ -0,0 +1,23 @@ +/* heh, this technically speaking would work but the templating turns out to be + * too much for both GCC and clang. With some manual intervention on the + * generated code I can get fibonacci numbers up to about 35 to work, but then + * I run out of stack space. I guess the compiler can't collapse frames so the + * bifurcating nature of fibonacci just gets mapped to a linear sequence of + * calls? */ + +fib(n, res) +{ +	fwd_if(n < 2) => { +		res(1); +	} => { +		fib(n - 1) => f1; +		fib(n - 2) => f2; +		res(f1 + f2); +	} +} + +main() +{ +	fib(6) => n; +	fwd_println(n); +}  | 
