mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 06:48:48 +00:00
This commit is contained in:
parent
4c736914d4
commit
2f640fdc68
9 changed files with 29 additions and 3 deletions
BIN
lama-spec.pdf
BIN
lama-spec.pdf
Binary file not shown.
|
|
@ -347,7 +347,9 @@ fresh list if images in the same order.}
|
|||
"\lstinline|Some (v)|" otherwise, where "\lstinline|v|"~--- the first value to satisfy "\lstinline|f|".
|
||||
}
|
||||
|
||||
\descr{\lstinline|fun flatten (l)|}{Flattens an arbitrary nesting of lists into a regular list. The order of elements is preserved in both senses.}
|
||||
\descr{\lstinline|fun flatten (l)|}{Flattens a list of lists into a regular list. The order of elements is preserved in both senses.}
|
||||
|
||||
\descr{\lstinline|fun deepFlatten (l)|}{Flattens an arbitrary nesting of lists of \emph{boxed} values into a regular list. The order of elements is preserved in both senses.}
|
||||
|
||||
\descr{\lstinline|fun zip (a, b)|}{Zips a pair of lists into the list of pairs. Does not work for lists of different lengths.}
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
let path = "/home/db/.opam/4.08.1/share/Lama"
|
||||
let path = "/home/db/.opam/ocaml-system.4.07.1/share/Lama"
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
let version = "Version 1.00, d06d9a250, Mon Sep 21 21:30:08 2020 +0300"
|
||||
let version = "Version 1.00, 4c736914d, Mon Sep 21 23:46:13 2020 +0300"
|
||||
|
|
|
|||
|
|
@ -84,6 +84,21 @@ public fun flatten (l) {
|
|||
curr [0] := new
|
||||
}
|
||||
|
||||
iter (fun (x) {iter (append, x)}, l);
|
||||
|
||||
res [1]
|
||||
}
|
||||
|
||||
public fun deepFlatten (l) {
|
||||
local res = [0, {}], curr = [res];
|
||||
|
||||
fun append (x) {
|
||||
local new = x : {};
|
||||
|
||||
curr [0][1] := new;
|
||||
curr [0] := new
|
||||
}
|
||||
|
||||
fun traverse (l) {
|
||||
case l of
|
||||
_ : _ -> iter (traverse, l)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
Flattening: 0
|
||||
Flattening: {0, 0, 0, 0}
|
||||
Flattening: 0
|
||||
Flattening: {1, 2, 3}
|
||||
Flattening: {1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||
|
|
|
|||
2
stdlib/regression/orig/test32.log
Normal file
2
stdlib/regression/orig/test32.log
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Flattening: 0
|
||||
Flattening: {A, B, C, D}
|
||||
|
|
@ -2,6 +2,7 @@ import List;
|
|||
import Array;
|
||||
|
||||
printf ("Flattening: %s\n", flatten ({}).string);
|
||||
printf ("Flattening: %s\n", flatten ({{0}, {0, 0, 0}}).string);
|
||||
printf ("Flattening: %s\n", flatten ({{}, {}, {}}).string);
|
||||
printf ("Flattening: %s\n", flatten ({1, 2, 3} : {}).string);
|
||||
printf ("Flattening: %s\n", flatten ({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}).string);
|
||||
|
|
|
|||
5
stdlib/regression/test32.lama
Normal file
5
stdlib/regression/test32.lama
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import List;
|
||||
import Array;
|
||||
|
||||
printf ("Flattening: %s\n", deepFlatten ({}).string);
|
||||
printf ("Flattening: %s\n", deepFlatten ({{A}, {B, {C}, D}}).string)
|
||||
Loading…
Add table
Add a link
Reference in a new issue