Yard/test.yard

31 lines
519 B
Plaintext
Raw Normal View History

2023-01-02 11:56:53 +00:00
@feature(io, conv)
2023-01-02 11:06:30 +00:00
@version(100)
@author(Sven Vogel)
2023-01-02 11:56:53 +00:00
-- compute the factorial
-- in a recursive and functional way
2023-01-02 11:06:30 +00:00
fac(x:int) = int {
despite x != 1 {
yield 1;
}
yield fac(x - 1) * x
}
2023-01-02 11:56:53 +00:00
number = rat 12.0 # this is a function without arguments and a braceless body
2023-01-02 11:06:30 +00:00
2023-01-02 11:56:53 +00:00
// main function
main = int {
2023-01-02 11:06:30 +00:00
2023-01-02 11:56:53 +00:00
result = fac(to_int(number));
2023-01-02 11:06:30 +00:00
2023-01-02 11:56:53 +00:00
println("The Factorial of " .. number() .. " is: " .. result);
2023-01-02 11:06:30 +00:00
2023-01-02 11:56:53 +00:00
x:int = 0;
until x > 9 {
println("" .. x);
x = x + 1
}
2023-01-02 11:06:30 +00:00
2023-01-02 11:56:53 +00:00
yield 0;
2023-01-02 11:06:30 +00:00
}