Hacker News new | ask | show | jobs
by emersonrsantos 2839 days ago
In Forth language would be:

  : fib 2dup + ;
2dup word duplicates n and n-1 elements and put it on the top of the stack.

+ word takes n and n-1 elements from the stack and sum them. The result goes on top of the stack.

Just start with 1 and 1 at the top of stack.

1 comments

That's some very concise code golf! It would be interesting in seeing how Forth compiles this under the hood.
Normally Forth is interpreted. Compiled Forth code is unlikely to look particularly clean or elegant.

(If you like languages with a very high density of functionality to symbol count, you should look at APL and its successor J)