Fibs and Facts

From The fun Wiki
Revision as of 12:43, 3 May 2022 by Hamster (talk | contribs) (→‎Fibonacci)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Fibonacci and Factorial are two of the basic examples for functional programming languages. Here we show their implementation in Wu.

Fibonacci

 fib n = (> 2 n) 1 (+ 1 (+ (fib (- n 1) (- n 2))));
 linfib x y n = (== 0 n) y (linfib y (+ x y) (- n 1));

Fib.png

Factorial

 fact n = (> 2 n) 1 (* n (fact (- n 1)));

or,

 fact n = foldr + 0 (range 1 n);