lama_byterun/regression/test044.lama

39 lines
804 B
Text
Raw Normal View History

2019-09-29 02:47:07 +03:00
local x, y, z;
2018-05-16 16:50:36 +03:00
fun zip (x) {
2019-03-07 19:06:04 +03:00
case x of Pair (x, y) ->
2018-05-16 16:50:36 +03:00
case x of
2019-03-07 19:06:04 +03:00
Nil -> return Nil
| Cons (x, xs) -> case y of
Nil -> return Nil
| Cons (y, ys) -> return Cons (Pair (x, y), zip (Pair (xs, ys)))
2018-05-16 16:50:36 +03:00
esac
esac
esac
}
fun unzip (x) {
case x of
2019-03-07 19:06:04 +03:00
Nil -> return Pair (Nil, Nil)
| Cons (Pair (x, y), tl) ->
2018-05-16 16:50:36 +03:00
case unzip (tl) of
2019-03-07 19:06:04 +03:00
Pair (xs, ys) -> return Pair (Cons (x, xs), Cons (y, ys))
2018-05-16 16:50:36 +03:00
esac
esac
}
fun printList (l) {
case l of
2019-03-07 19:06:04 +03:00
Nil -> skip
| Cons (x, xs) -> write (x); printList (xs)
2018-05-16 16:50:36 +03:00
esac
}
z := read ();
2019-03-07 19:06:04 +03:00
x := Cons (1, Cons (2, Cons (3, Nil)));
y := Cons (100, Cons (200, Cons (300, Nil)));
2018-05-16 16:50:36 +03:00
2019-03-07 19:06:04 +03:00
case unzip (zip (Pair (x, y))) of
Pair (x, y) -> printList (x); printList (y)
2018-05-16 16:50:36 +03:00
esac