Constructors capitalized

This commit is contained in:
Dmitry Boulytchev 2019-03-07 19:06:04 +03:00
parent 3bf36ae719
commit 4879a02753
18 changed files with 147 additions and 145 deletions

View file

@ -15,8 +15,7 @@
32
51
93
96
99
67
111
110
115
@ -25,8 +24,7 @@
49
44
32
96
99
67
111
110
115
@ -35,8 +33,7 @@
50
44
32
96
110
78
105
108
41

View file

@ -1,21 +1,21 @@
fun append (x, y) {
case x of
`nil -> return y
| `cons (h, t) -> return `cons (h, append (t, y))
Nil -> return y
| Cons (h, t) -> return Cons (h, append (t, y))
esac
}
fun printList (x) {
case x of
`nil -> skip
| `cons (h, t) -> write (h); printList (t)
Nil -> skip
| Cons (h, t) -> write (h); printList (t)
esac
}
n := read ();
x := `cons (1, `cons (2, `nil));
y := `cons (3, `cons (4, `nil));
x := Cons (1, Cons (2, Nil));
y := Cons (3, Cons (4, Nil));
printList (x);
printList (y);

View file

@ -1,17 +1,17 @@
fun insert (t, x) {
case t of
`leaf -> return `node (x, `leaf, `leaf)
| `node (y, l, r) -> if x > y
then return `node (y, insert (l, x), r)
else return `node (y, l, insert (r, x))
Leaf -> return Node (x, Leaf, Leaf)
| Node (y, l, r) -> if x > y
then return Node (y, insert (l, x), r)
else return Node (y, l, insert (r, x))
fi
esac
}
fun find (t, x) {
case t of
`leaf -> return 0
| `node (y, l, r) -> if x == y then return 1
Leaf -> return 0
| Node (y, l, r) -> if x == y then return 1
elif x > y then return find (l, x)
else return find (r, x)
fi
@ -20,7 +20,7 @@ fun find (t, x) {
n := read ();
t := insert (insert (insert (insert (`leaf, 5), 4), 6), 3);
t := insert (insert (insert (insert (Leaf, 5), 4), 6), 3);
write (find (t, 5));
write (find (t, 4));

View file

@ -1,15 +1,15 @@
fun f (x) {
case x of
`a -> write (1)
| `b -> write (2)
| `c -> write (3)
A -> write (1)
| B -> write (2)
| C -> write (3)
| _ -> write (4)
esac
}
x := read ();
f (`a);
f (`b);
f (`c);
f (`d)
f (A);
f (B);
f (C);
f (D)

View file

@ -1,11 +1,11 @@
fun f (a) {
case a of
`a (x, y, z) -> write (x + y + z)
| `b (x, y, z) -> write (x + y + z)
A (x, y, z) -> write (x + y + z)
| B (x, y, z) -> write (x + y + z)
esac
}
x := read ();
f (`a (100, 200, 300));
f (`b (500, 600, 700))
f (A (100, 200, 300));
f (B (500, 600, 700))

View file

@ -1,17 +1,17 @@
fun f (x) {
case x of
`nil -> write (0)
| `cons (_, `nil) -> write (1)
| `cons (_, `cons (_, `nil)) -> write (2)
| `cons (_, `cons (_, `cons (_, `nil))) -> write (3)
| _ -> write (4)
Nil -> write (0)
| Cons (_, Nil) -> write (1)
| Cons (_, Cons (_, Nil)) -> write (2)
| Cons (_, Cons (_, Cons (_, Nil))) -> write (3)
| _ -> write (4)
esac
}
x := read ();
y := `nil;
y := Nil;
for i := 0, i < 10, i := i + 1 do
f (y);
y := `cons (i, y)
y := Cons (i, y)
od

View file

@ -1,12 +1,12 @@
fun sum (x) {
case x of
`nil -> return 0
| `cons (x, tl) -> return x + sum (tl)
Nil -> return 0
| Cons (x, tl) -> return x + sum (tl)
esac
}
x := read ();
write (sum (`nil));
write (sum (`cons (100, `nil)));
write (sum (`cons (100, `cons (200, `nil))))
write (sum (Nil));
write (sum (Cons (100, Nil)));
write (sum (Cons (100, Cons (200, Nil))))

View file

@ -1,10 +1,10 @@
fun zip (x) {
case x of `pair (x, y) ->
case x of Pair (x, y) ->
case x of
`nil -> return `nil
| `cons (x, xs) -> case y of
`nil -> return `nil
| `cons (y, ys) -> return `cons (`pair (x, y), zip (`pair (xs, ys)))
Nil -> return Nil
| Cons (x, xs) -> case y of
Nil -> return Nil
| Cons (y, ys) -> return Cons (Pair (x, y), zip (Pair (xs, ys)))
esac
esac
esac
@ -12,26 +12,26 @@ fun zip (x) {
fun unzip (x) {
case x of
`nil -> return `pair (`nil, `nil)
| `cons (`pair (x, y), tl) ->
Nil -> return Pair (Nil, Nil)
| Cons (Pair (x, y), tl) ->
case unzip (tl) of
`pair (xs, ys) -> return `pair (`cons (x, xs), `cons (y, ys))
Pair (xs, ys) -> return Pair (Cons (x, xs), Cons (y, ys))
esac
esac
}
fun printList (l) {
case l of
`nil -> skip
| `cons (x, xs) -> write (x); printList (xs)
Nil -> skip
| Cons (x, xs) -> write (x); printList (xs)
esac
}
z := read ();
x := `cons (1, `cons (2, `cons (3, `nil)));
y := `cons (100, `cons (200, `cons (300, `nil)));
x := Cons (1, Cons (2, Cons (3, Nil)));
y := Cons (100, Cons (200, Cons (300, Nil)));
case unzip (zip (`pair (x, y))) of
`pair (x, y) -> printList (x); printList (y)
case unzip (zip (Pair (x, y))) of
Pair (x, y) -> printList (x); printList (y)
esac

View file

@ -9,4 +9,4 @@ printString (1.string);
printString ("abc".string);
printString ([].string);
printString ([1, 2, 3].string);
printString (`cons (1, `cons (2, `nil)).string)
printString (Cons (1, Cons (2, Nil)).string)

View file

@ -13,26 +13,26 @@ case 3 of
a@_ -> write (a)
esac;
case `a (1, 2, 3) of
`a -> write (1)
| a@`a (_, _, _) -> case a of
`a (x, y, z) -> write (x); write (y); write (z)
case A (1, 2, 3) of
A -> write (1)
| a@A (_, _, _) -> case a of
A (x, y, z) -> write (x); write (y); write (z)
esac
esac;
case `a (1, 2, 3, 4, 5) of
`a -> write (0)
| `a (_) -> write (1)
| `a (_, _) -> write (2)
| `a (_, _, _) -> write (3)
| `a (_, _, _, _) -> write (4)
| `a (_, _, _, _, _) -> write (5)
case A (1, 2, 3, 4, 5) of
A -> write (0)
| A (_) -> write (1)
| A (_, _) -> write (2)
| A (_, _, _) -> write (3)
| A (_, _, _, _) -> write (4)
| A (_, _, _, _, _) -> write (5)
esac;
write (`a (1, 2, 3, 4, 5).length);
write (A (1, 2, 3, 4, 5).length);
write (`a (1, 2, 3, 4, 5)[0]);
write (`a (1, 2, 3, 4, 5)[1]);
write (`a (1, 2, 3, 4, 5)[2]);
write (`a (1, 2, 3, 4, 5)[3]);
write (`a (1, 2, 3, 4, 5)[4])
write (A (1, 2, 3, 4, 5)[0]);
write (A (1, 2, 3, 4, 5)[1]);
write (A (1, 2, 3, 4, 5)[2]);
write (A (1, 2, 3, 4, 5)[3]);
write (A (1, 2, 3, 4, 5)[4])

View file

@ -1,6 +1,6 @@
fun collect_ints_acc (v, tail) local i {
case v of
a@#unboxed -> return `cons (a, tail)
a@#unboxed -> return Cons (a, tail)
| #string -> return tail
| _ ->
for i := 0, i < v.length, i := i + 1 do
@ -11,13 +11,13 @@ fun collect_ints_acc (v, tail) local i {
}
fun collect_ints (v) {
return collect_ints_acc (v, `nil)
return collect_ints_acc (v, Nil)
}
fun print_list (l) {
case l of
`nil -> skip
| `cons (n, t) -> write (n); print_list (t)
Nil -> skip
| Cons (n, t) -> write (n); print_list (t)
esac
}
@ -41,11 +41,11 @@ case 1 of
| a@0 -> write (a)
esac;
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)
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)
esac;
case "abc" of
@ -69,4 +69,4 @@ case [1, 2, 3] of
| [a, b, c] -> write (a); write (b); write (c)
esac;
print_list (collect_ints ([1, 2, 3, [4, 5, 6, `cons (1, 2, 3)]]))
print_list (collect_ints ([1, 2, 3, [4, 5, 6, Cons (1, 2, 3)]]))

View file

@ -1,12 +1,12 @@
`Empty
`Node (0, `Empty, `Empty)
`Node (0, `Empty, `Node (1, `Empty, `Empty))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Empty)))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Node (3, `Empty, `Empty))))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Node (3, `Empty, `Node (4, `Empty, `Empty)))))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Node (3, `Empty, `Node (4, `Empty, `Node (5, `Empty, `Empty))))))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Node (3, `Empty, `Node (4, `Empty, `Node (5, `Empty, `Node (6, `Empty, `Empty)))))))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Node (3, `Empty, `Node (4, `Empty, `Node (5, `Empty, `Node (6, `Empty, `Node (7, `Empty, `Empty))))))))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Node (3, `Empty, `Node (4, `Empty, `Node (5, `Empty, `Node (6, `Empty, `Node (7, `Empty, `Node (8, `Empty, `Empty)))))))))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Node (3, `Empty, `Node (4, `Empty, `Node (5, `Empty, `Node (6, `Empty, `Node (7, `Empty, `Node (8, `Empty, `Node (9, `Empty, `Empty))))))))))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Node (3, `Empty, `Node (4, `Empty, `Node (5, `Empty, `Node (6, `Empty, `Node (7, `Empty, `Node (8, `Empty, `Node (9, `Empty, `Node (10, `Empty, `Empty)))))))))))
Empty
Node (0, Empty, Empty)
Node (0, Empty, Node (1, Empty, Empty))
Node (0, Empty, Node (1, Empty, Node (2, Empty, Empty)))
Node (0, Empty, Node (1, Empty, Node (2, Empty, Node (3, Empty, Empty))))
Node (0, Empty, Node (1, Empty, Node (2, Empty, Node (3, Empty, Node (4, Empty, Empty)))))
Node (0, Empty, Node (1, Empty, Node (2, Empty, Node (3, Empty, Node (4, Empty, Node (5, Empty, Empty))))))
Node (0, Empty, Node (1, Empty, Node (2, Empty, Node (3, Empty, Node (4, Empty, Node (5, Empty, Node (6, Empty, Empty)))))))
Node (0, Empty, Node (1, Empty, Node (2, Empty, Node (3, Empty, Node (4, Empty, Node (5, Empty, Node (6, Empty, Node (7, Empty, Empty))))))))
Node (0, Empty, Node (1, Empty, Node (2, Empty, Node (3, Empty, Node (4, Empty, Node (5, Empty, Node (6, Empty, Node (7, Empty, Node (8, Empty, Empty)))))))))
Node (0, Empty, Node (1, Empty, Node (2, Empty, Node (3, Empty, Node (4, Empty, Node (5, Empty, Node (6, Empty, Node (7, Empty, Node (8, Empty, Node (9, Empty, Empty))))))))))
Node (0, Empty, Node (1, Empty, Node (2, Empty, Node (3, Empty, Node (4, Empty, Node (5, Empty, Node (6, Empty, Node (7, Empty, Node (8, Empty, Node (9, Empty, Node (10, Empty, Empty)))))))))))

View file

@ -6,4 +6,4 @@
2
3
100
`cons (3, `cons (2, `cons (1, `cons (6, `cons (5, `cons (4, `cons (3, `cons (2, `cons (1, `nil)))))))))
Cons (3, Cons (2, Cons (1, Cons (6, Cons (5, Cons (4, Cons (3, Cons (2, Cons (1, Nil)))))))))

View file

@ -1,15 +1,15 @@
fun insert (tree, value) {
case tree of
`Empty -> return `Node (value, `Empty, `Empty)
| `Node (x, left, right) ->
Empty -> return Node (value, Empty, Empty)
| Node (x, left, right) ->
if x > value
then return `Node (x, insert (left, value), right)
else return `Node (x, left, insert (right, value))
then return Node (x, insert (left, value), right)
else return Node (x, left, insert (right, value))
fi
esac
}
tree := `Empty;
tree := Empty;
for i := 0, i <= 10, i := i+1 do
printf ("%s\n", tree.string);

View file

@ -1,6 +1,6 @@
fun collect_ints_acc (v, tail) local i {
case v of
a@#unboxed -> return `cons (a, tail)
a@#unboxed -> return Cons (a, tail)
| #string -> return tail
| _ ->
for i := 0, i < v.length, i := i + 1 do
@ -11,7 +11,7 @@ fun collect_ints_acc (v, tail) local i {
}
fun collect_ints (v) {
return collect_ints_acc (v, `nil)
return collect_ints_acc (v, Nil)
}
case 1 of
@ -32,11 +32,11 @@ case 1 of
| a@0 -> write (a)
esac;
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)
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)
esac;
case "abc" of
@ -60,4 +60,4 @@ case [1, 2, 3] of
| [a, b, c] -> write (a); write (b); write (c)
esac;
printf ("%s\n", collect_ints ([1, 2, 3, [4, 5, 6, `cons (1, 2, 3)]]).string)
printf ("%s\n", collect_ints ([1, 2, 3, [4, 5, 6, Cons (1, 2, 3)]]).string)