diff --git a/lama-spec.pdf b/lama-spec.pdf index 32d3cbc1f..75fcbf8f8 100644 Binary files a/lama-spec.pdf and b/lama-spec.pdf differ diff --git a/spec/07.standard_library.tex b/spec/07.standard_library.tex index 1f3f01129..1d9b5a6c3 100644 --- a/spec/07.standard_library.tex +++ b/spec/07.standard_library.tex @@ -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.} diff --git a/src/stdpath.ml b/src/stdpath.ml index fa0d92a24..f3cd19db9 100644 --- a/src/stdpath.ml +++ b/src/stdpath.ml @@ -1 +1 @@ -let path = "/home/db/.opam/4.08.1/share/Lama" +let path = "/home/db/.opam/ocaml-system.4.07.1/share/Lama" diff --git a/src/version.ml b/src/version.ml index 3d9a2aff6..e5cfd5503 100644 --- a/src/version.ml +++ b/src/version.ml @@ -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" diff --git a/stdlib/List.lama b/stdlib/List.lama index 4ed5f856e..15d7f76d4 100644 --- a/stdlib/List.lama +++ b/stdlib/List.lama @@ -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) diff --git a/stdlib/regression/orig/test06.log b/stdlib/regression/orig/test06.log index c4ed9eda0..685f6aaab 100644 --- a/stdlib/regression/orig/test06.log +++ b/stdlib/regression/orig/test06.log @@ -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} diff --git a/stdlib/regression/orig/test32.log b/stdlib/regression/orig/test32.log new file mode 100644 index 000000000..898989cb5 --- /dev/null +++ b/stdlib/regression/orig/test32.log @@ -0,0 +1,2 @@ +Flattening: 0 +Flattening: {A, B, C, D} diff --git a/stdlib/regression/test06.lama b/stdlib/regression/test06.lama index b0117889f..e5ff34864 100644 --- a/stdlib/regression/test06.lama +++ b/stdlib/regression/test06.lama @@ -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); diff --git a/stdlib/regression/test32.lama b/stdlib/regression/test32.lama new file mode 100644 index 000000000..138347f33 --- /dev/null +++ b/stdlib/regression/test32.lama @@ -0,0 +1,5 @@ +import List; +import Array; + +printf ("Flattening: %s\n", deepFlatten ({}).string); +printf ("Flattening: %s\n", deepFlatten ({{A}, {B, {C}, D}}).string)