Skip to content

Commit 551f024

Browse files
committed
merge
1 parent 7ff7ced commit 551f024

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

__test__/satysrc/generic.saty

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ let () = Debug.log (String.of-int (Ref.get r)) in % 1
5353

5454
let () = Debug.log `==== String ====` in
5555
let () = Debug.log (String.concat [`a`; `b`; `c`;]) in
56-
let () = Debug.log (String.with-concat `;` [`a`; `b`; `c`;]) in
56+
let () = Debug.log (String.concat ?:(`;`) [`a`; `b`; `c`;]) in
5757
let () = Debug.log (String.of-bool (String.is-empty ` `)) in % true
5858
let _ = String.split-by (Char.make `;`) `spam;ham;eggs;` |> List.map Debug.log in
5959
let _ = String.to-list `abc` |> List.map (fun c -> (c |> String.of-char |> Debug.log)) in
@@ -360,7 +360,7 @@ let () = Debug.log `==== TreeSet ====` in
360360
% REMARK:
361361
% This test relies on the fact that the order of elements of a result from TreeSet.to-list is
362362
% level-order (BFS). If the implementation is changed, the following tests have to be updated.
363-
let p s = s |> TreeSet.to-list |> List.map String.of-int |> List.intersperse `,` |> String.concat |> Debug.log in
363+
let p s = s |> TreeSet.to-list |> List.map String.of-int |> List.intersperse `,` |> (fun l -> String.concat l) |> Debug.log in
364364
let s = TreeSet.empty in
365365
let () = p s in
366366
let s = TreeSet.of-list Int.ord [3;2;3;1] in

src/string.satyg

+15-11
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ module String : sig
2626
val of-char : Char.t -> string
2727
val of-length : length -> string
2828
val append : string -> string -> string
29-
val with-concat : string -> string list -> string
30-
val concat : string list -> string
31-
val cat : string -> string -> string
29+
val concat : string ?-> string list -> string
3230
val is-empty : string -> bool
3331
val starts-with : string -> string -> bool
3432
val ends-with : string -> string -> bool
@@ -67,15 +65,21 @@ end = struct
6765
let append s1 s2 = s1 ^ s2
6866

6967

70-
let-rec with-concat s xs =
71-
match xs with
72-
| [] -> empty
73-
| [x] -> x
74-
| x :: xs -> x ^ s ^ with-concat s xs
7568

76-
let concat xs = with-concat empty xs
69+
let concat ?:s xs =
70+
let s =
71+
match s with
72+
| None -> empty
73+
| Some(s) -> s
74+
in
75+
let-rec sub xs =
76+
match xs with
77+
| [] -> empty
78+
| [x] -> x
79+
| x :: xs -> x ^ s ^ sub xs
80+
in
81+
sub xs
7782

78-
let cat = (^)
7983

8084
let is-empty s =
8185
equal s empty
@@ -96,7 +100,7 @@ end = struct
96100
|> List.map Char.of-codepoint
97101

98102
let of-list chars =
99-
chars |> List.map Char.to-string |> concat
103+
chars |> List.map Char.to-string |> (fun slst -> concat slst)
100104

101105
let pow n s =
102106
let-rec go i acc = if i == n then acc else go (i + 1) (acc ^ s) in

0 commit comments

Comments
 (0)