|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Navigation |
Synopsis Func is a tiny functional language; we present several interpreters for it.
Description Func is a functional language with the following features:
Examples Here are several versions of the factorial function
that use more and more features of the Func language:
F0.func:
fact(n) = if n <= 1 then
1
else
n * fact(n-1)
end
F1.func:
fact(n) = let
x = n
in
if x <= 1 then
x
else
x * fact(x-1)
end
end
F2.func:
fact(n) = if n <= 1 then
n := 1
else
n := n * fact(n-1)
end;
n
F3.func:
swap(a, b) =
let
temp = *a
in
*a := *b;
*b := temp
end
fact(n) = let
x = 1,
y = 0
in
if n <= 1 then
x := 1
else
x := n * fact(n-1)
end;
swap(&x, &y);
y
end
For convenience, we use two versions of these examples for each Fi:
F0.rsc looks like this (note the escaped < character).
module demo::lang::Func::programs::F0
public str F0 =
"fact(n) = if n \<= 1 then
1
else
n * fact(n-1)
end";
|