lama_byterun/stdlib/regression/test21.lama

66 lines
1.1 KiB
Text
Raw Normal View History

2019-11-19 03:24:17 +03:00
fun collect_ints_acc (v, tail) {
local i;
2018-11-06 14:03:55 +03:00
case v of
2021-01-31 19:11:03 +03:00
a@#unboxed -> Cons (a, tail)
| #string -> tail
2018-11-06 14:03:55 +03:00
| _ ->
for i := 0, i < v.length, i := i + 1 do
tail := collect_ints_acc (v[i], tail)
od;
2021-01-31 19:11:03 +03:00
tail
2018-11-06 14:03:55 +03:00
esac
}
fun collect_ints (v) {
2021-01-31 19:11:03 +03:00
collect_ints_acc (v, Nil)
2018-11-06 14:03:55 +03:00
}
case 1 of
5 -> write (5)
| 4 -> write (4)
| 3 -> write (3)
| 2 -> write (2)
| 1 -> write (1)
| 0 -> write (0)
esac;
case 1 of
a@5 -> write (a)
| a@4 -> write (a)
| a@3 -> write (a)
| a@2 -> write (a)
| a@1 -> write (a)
| a@0 -> write (a)
esac;
2019-03-07 19:06:04 +03:00
case A (1, 2, 3) of
A (1, 3, 5) -> write (0)
| A (3, 4, 5) -> write (0)
| A (1, 2, 3) -> write (1)
| A (6, 7, 8) -> write (0)
2018-11-06 14:03:55 +03:00
esac;
case "abc" of
"def" -> write (0)
| "ab" -> write (0)
| "abc" -> write (1)
| "" -> write (0)
esac;
case [1, 2, 3] of
[] -> write (0)
| [a, b] -> write (0)
| [a, b, c] -> write (a); write (b); write (c)
| [_, _, _] -> write (0)
esac;
case [1, 2, 3] of
[] -> write (0)
| [a, b] -> write (0)
| [_, _, _] -> write (100)
| [a, b, c] -> write (a); write (b); write (c)
esac;
2019-03-07 19:06:04 +03:00
printf ("%s\n", collect_ints ([1, 2, 3, [4, 5, 6, Cons (1, 2, 3)]]).string)