lama_byterun/regression/test085.lama

28 lines
424 B
Text
Raw Normal View History

2020-01-05 03:33:17 +03:00
fun sum (l) {
case l of
{} -> 0
| h : t -> (h + sum (t))
esac
}
fun print_list (l) {
case l of
{} -> skip
| h : t -> write (h); print_list (t)
esac
}
fun array_to_list (a) {
var l, i;
2020-01-05 03:33:17 +03:00
l := {};
for i := a.length, i > 0, i := i-1 do
l := a[i-1] : l
od;
l
}
write (sum ({}));
write (sum ({1, 2, 3, 4, 5}));
write (sum (1:2:3:4:5:{}));
print_list (array_to_list ([1, 2, 3, 4, 5]))