Fibs and Facts

From The fun Wiki
Revision as of 12:22, 3 May 2022 by Hamster (talk | contribs) (Created page with "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...")
(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));

Factorial

 fact n = (> 2 n) 1 (* n (fact (- n 1)));
 fact n = foldr + 0 (range 1 n);