mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 06:48:48 +00:00
List notations/pattern matching
This commit is contained in:
parent
4879a02753
commit
e16fb72a9e
8 changed files with 128 additions and 20 deletions
8
regression/orig/test051.log
Normal file
8
regression/orig/test051.log
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
> 0
|
||||
15
|
||||
15
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
28
regression/test051.expr
Normal file
28
regression/test051.expr
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
fun sum (l) {
|
||||
case l of
|
||||
{} -> return 0
|
||||
| h : t -> return (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) local l, i {
|
||||
l := {};
|
||||
for i := a.length, i > 0, i := i-1 do
|
||||
l := a[i-1] : l
|
||||
od;
|
||||
return l
|
||||
}
|
||||
|
||||
n := read ();
|
||||
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]))
|
||||
|
||||
1
regression/test051.input
Normal file
1
regression/test051.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
4
regression/x86only/orig/test003.log
Normal file
4
regression/x86only/orig/test003.log
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
0
|
||||
{1, 2, 3, 4}
|
||||
{{1}, {2, 3}, {4, {5, 6}}}
|
||||
{1, 2, 3, 4}
|
||||
10
regression/x86only/test003.expr
Normal file
10
regression/x86only/test003.expr
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
lists := [
|
||||
{},
|
||||
{1, 2, 3, 4},
|
||||
{{1}, {2, 3}, {4, {5, 6}}},
|
||||
1 : 2 : 3 : 4 : {}
|
||||
];
|
||||
|
||||
for i := 0, i<lists.length, i:=i+1 do
|
||||
printf ("%s\n", lists[i].string)
|
||||
od
|
||||
1
regression/x86only/test003.input
Normal file
1
regression/x86only/test003.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
Loading…
Add table
Add a link
Reference in a new issue