Skip to content

Commit 27619c9

Browse files
committed
fix syntax
1 parent 7e4a87c commit 27619c9

8 files changed

Lines changed: 44 additions & 40 deletions

File tree

trilogy/src/stdlib/array.tri

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func reduce f [x, ..xs] = fold f x xs
112112

113113
test "array reduce" {
114114
assert reduce (+) [1, 2, 3, 4] == 10
115-
assert with (reduce (+) []; false) { when 'mia cancel true }
115+
assert with { reduce (+) []; false } { when 'mia cancel true }
116116
assert reduce (:) [1, 2, 3] == (1:2):3
117117
}
118118

@@ -121,7 +121,7 @@ func rreduce f [..xs, x] = rfold f x xs
121121

122122
test "array rreduce" {
123123
assert rreduce (+) [1, 2, 3, 4] == 10
124-
assert with (rreduce (+) []; false) { when 'mia cancel true }
124+
assert with { rreduce (+) []; false } { when 'mia cancel true }
125125
assert rreduce (:) [1, 2, 3] == (3:2):1
126126
}
127127

@@ -168,31 +168,31 @@ func first [x, .._] = x
168168

169169
test "array first" {
170170
assert first [1, 2, 3] == 1
171-
assert with (first []; false) { when 'mia cancel true }
171+
assert with { first []; false } { when 'mia cancel true }
172172
}
173173

174174
func last [] = yield 'mia
175175
func last [.._, x] = x
176176

177177
test "array last" {
178178
assert last [1, 2, 3] == 3
179-
assert with (last []; false) { when 'mia cancel true }
179+
assert with { last []; false } { when 'mia cancel true }
180180
}
181181

182182
func tail [] = yield 'mia
183183
func tail [_, ..xs] = xs
184184

185185
test "array tail" {
186186
assert tail [1, 2, 3] == [2, 3]
187-
assert with (tail []; false) { when 'mia cancel true }
187+
assert with { tail []; false } { when 'mia cancel true }
188188
}
189189

190190
func head [] = yield 'mia
191191
func head [..xs, _] = xs
192192

193193
test "array head" {
194194
assert head [1, 2, 3] == [1, 2]
195-
assert with (head []; false) { when 'mia cancel true }
195+
assert with { head []; false } { when 'mia cancel true }
196196
}
197197

198198
func slice i fin (arr and typeof 'array) = core::slice i fin arr
@@ -202,10 +202,10 @@ test "array slice" {
202202
assert slice 1 2 [1, 2, 3] == [2]
203203
assert slice 1 1 [1, 2, 3] == []
204204
assert slice 1 3 [1, 2, 3] == [2, 3]
205-
assert with (slice (-1) 2 [1, 2, 3]; false) { when 'arg cancel true }
206-
assert with (slice 2 1 [1, 2, 3]; false) { when 'arg cancel true }
207-
assert with (slice 0 5 [1, 2, 3]; false) { when 'mia cancel true }
208-
assert with (slice 5 5 [1, 2, 3]; false) { when 'mia cancel true }
205+
assert with { slice (-1) 2 [1, 2, 3]; false } { when 'arg cancel true }
206+
assert with { slice 2 1 [1, 2, 3]; false } { when 'arg cancel true }
207+
assert with { slice 0 5 [1, 2, 3]; false } { when 'mia cancel true }
208+
assert with { slice 5 5 [1, 2, 3]; false } { when 'mia cancel true }
209209
}
210210

211211
func take n (arr and typeof 'array) =
@@ -219,7 +219,7 @@ test "array take" {
219219
assert take 2 [1, 2, 3] == [1, 2]
220220
assert take 3 [1, 2, 3] == [1, 2, 3]
221221
assert take 12 [1, 2, 3] == [1, 2, 3]
222-
assert with (take (-1) [1, 2, 3]; false) { when 'arg cancel true }
222+
assert with { take (-1) [1, 2, 3]; false } { when 'arg cancel true }
223223
}
224224

225225
func skip n (arr and typeof 'array) =
@@ -233,7 +233,7 @@ test "array skip" {
233233
assert skip 2 [1, 2, 3] == [3]
234234
assert skip 3 [1, 2, 3] == []
235235
assert skip 12 [1, 2, 3] == []
236-
assert with (skip (-1) [1, 2, 3]; false) { when 'arg cancel true }
236+
assert with { skip (-1) [1, 2, 3]; false } { when 'arg cancel true }
237237
}
238238

239239
func drop n (arr and typeof 'array) =
@@ -247,12 +247,12 @@ test "array drop" {
247247
assert drop 2 [1, 2, 3] == [1]
248248
assert drop 3 [1, 2, 3] == []
249249
assert drop 12 [1, 2, 3] == []
250-
assert with (drop (-1) [1, 2, 3]; false) { when 'arg cancel true }
250+
assert with { drop (-1) [1, 2, 3]; false } { when 'arg cancel true }
251251
}
252252

253253
func collect iterator =
254254
let arr = [],
255-
with (iterator!(); arr) {
255+
with { iterator!(); arr } {
256256
when 'next(val) then {
257257
push!(arr, val)
258258
become unit

trilogy/src/stdlib/debug.tri

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ proc dbg!(value) {
6161
return value
6262
}
6363

64-
func trace label value =
65-
core::print!("${to_string label}: ${to_string value}\n");
64+
func trace label value = {
65+
core::print!("${to_string label}: ${to_string value}\n")
6666
value
67+
}

trilogy/src/stdlib/heap.tri

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ type heap cmp {
2323
}
2424
}
2525

26-
func append val [..heap] = push!(heap, val); heap
26+
func append val [..heap] = {
27+
push!(heap, val)
28+
heap
29+
}
2730

2831
proc pop!(heap) {
2932
swap!(heap, 0, length heap - 1)
@@ -52,7 +55,7 @@ type heap cmp {
5255

5356
func collect iterator =
5457
let heap = [],
55-
with (iterator!(); heap) {
58+
with { iterator!(); heap } {
5659
when 'next(val) then {
5760
push!(heap, val)
5861
become unit

trilogy/src/stdlib/iterator.tri

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ test "iterator scan" {
192192

193193
func fold f a it =
194194
let mut state = a,
195-
with it!(); state {
195+
with { it!(); state } {
196196
when 'next(val) then {
197197
state = f state val
198198
become unit
@@ -205,13 +205,13 @@ test "iterator fold" {
205205

206206
func reduce f it =
207207
let mut state = 'none,
208-
with
209-
it!();
208+
with {
209+
it!()
210210
match state {
211211
case 'some(v) then v
212212
else yield 'mia
213213
}
214-
{
214+
} {
215215
when 'next(val) then {
216216
state = match state {
217217
case 'some(prev) then 'some(f prev val)
@@ -239,7 +239,7 @@ test "iterator count" {
239239
}
240240

241241
func any predicate it =
242-
with it!(); false {
242+
with { it!(); false } {
243243
when 'next(val) then {
244244
if predicate val {
245245
return true
@@ -255,7 +255,7 @@ test "iterator any" {
255255
}
256256

257257
func all predicate it =
258-
with it!(); true {
258+
with { it!(); true } {
259259
when 'next(val) then {
260260
if !(predicate val) {
261261
return false
@@ -286,7 +286,7 @@ test "iterator enumerate" {
286286
}
287287

288288
func find p it =
289-
with it!(); yield 'mia {
289+
with { it!(); yield 'mia } {
290290
when 'next(v) then {
291291
if p v {
292292
return v
@@ -313,7 +313,7 @@ test "iterator choose" {
313313
}
314314

315315
func for_each f it =
316-
with it!(); unit {
316+
with { it!(); unit } {
317317
when 'next(v) then {
318318
f v
319319
become unit

trilogy/src/stdlib/parsec.tri

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ proc digit!() {
248248

249249
test "parsec digit" {
250250
assert parse digit "123" == '1'
251-
assert with parse digit "A"; false { when 'reject(_) cancel true else cancel false }
251+
assert with { parse digit "A"; false } { when 'reject(_) cancel true else cancel false }
252252
}
253253

254254
## A parser for any base-16 digit.
@@ -259,7 +259,7 @@ proc hex_digit!() {
259259
test "parsec hex_digit" {
260260
assert parse hex_digit "123" == '1'
261261
assert parse hex_digit "abc" == 'a'
262-
assert with parse hex_digit "Z"; false { when 'reject(_) cancel true else cancel false }
262+
assert with { parse hex_digit "Z"; false } { when 'reject(_) cancel true else cancel false }
263263
}
264264

265265
## Parses a base-10 integer from a string, returning the value as a number. A leading `-` sign
@@ -300,7 +300,7 @@ proc letter!() {
300300

301301
test "parsec letter" {
302302
assert parse letter "a" == 'a'
303-
assert with parse letter "1"; false { when 'reject(_) cancel true else cancel false }
303+
assert with { parse letter "1"; false } { when 'reject(_) cancel true else cancel false }
304304
}
305305

306306
## A parser for any ASCII whitespace.
@@ -310,7 +310,7 @@ proc whitespace!() {
310310

311311
test "parsec whitespace" {
312312
assert parse whitespace " " == ' '
313-
assert with parse whitespace "1"; false { when 'reject(_) cancel true else cancel false }
313+
assert with { parse whitespace "1"; false } { when 'reject(_) cancel true else cancel false }
314314
}
315315

316316
## A parser for any word (a sequence of word characters `[A-Za-z0-9_]`).

trilogy/src/stdlib/record.tri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test "record contains_key" {
2929

3030
func collect iterator =
3131
let record = {||},
32-
with (iterator!(); record) {
32+
with { iterator!(); record } {
3333
when 'next(key:val) then {
3434
record.key = val
3535
become unit

trilogy/src/stdlib/set.tri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ test "set contains" {
5151

5252
func collect iterator =
5353
let set = [||],
54-
with (iterator!(); set) {
54+
with { iterator!(); set } {
5555
when 'next(val) then {
5656
push!(set, val)
5757
become unit

trilogy/src/stdlib/string.tri

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ test "string slice" {
4343
assert slice 1 2 "123" == "2"
4444
assert slice 1 1 "123" == ""
4545
assert slice 1 3 "123" == "23"
46-
assert with (slice (-1) 2 "123"; false) { when 'arg cancel true }
47-
assert with (slice 2 1 "123"; false) { when 'arg cancel true }
48-
assert with (slice 0 5 "123"; false) { when 'mia cancel true }
49-
assert with (slice 5 5 "123"; false) { when 'mia cancel true }
46+
assert with { slice (-1) 2 "123"; false } { when 'arg cancel true }
47+
assert with { slice 2 1 "123"; false } { when 'arg cancel true }
48+
assert with { slice 0 5 "123"; false } { when 'mia cancel true }
49+
assert with { slice 5 5 "123"; false } { when 'mia cancel true }
5050
}
5151

5252
func take n (str and typeof 'string) =
@@ -60,7 +60,7 @@ test "string take" {
6060
assert take 2 "123" == "12"
6161
assert take 3 "123" == "123"
6262
assert take 12 "123" == "123"
63-
assert with (take (-1) "123"; false) { when 'arg cancel true }
63+
assert with { take (-1) "123"; false } { when 'arg cancel true }
6464
}
6565

6666
func skip n (str and typeof 'string) =
@@ -74,7 +74,7 @@ test "string skip" {
7474
assert skip 2 "123" == "3"
7575
assert skip 3 "123" == ""
7676
assert skip 12 "123" == ""
77-
assert with (skip (-1) "123"; false) { when 'arg cancel true }
77+
assert with { skip (-1) "123"; false } { when 'arg cancel true }
7878
}
7979

8080
func drop n (str and typeof 'string) =
@@ -88,7 +88,7 @@ test "string drop" {
8888
assert drop 2 "123" == "1"
8989
assert drop 3 "123" == ""
9090
assert drop 12 "123" == ""
91-
assert with (drop (-1) "123"; false) { when 'arg cancel true }
91+
assert with { drop (-1) "123"; false } { when 'arg cancel true }
9292
}
9393

9494
func starts_with prefix string = take (length prefix) string == prefix
@@ -194,7 +194,7 @@ test "string split" {
194194

195195
func collect iterator =
196196
let mut str = "",
197-
with (iterator!(); str) {
197+
with { iterator!(); str } {
198198
when 'next(val) then {
199199
str <>= core::to_string val
200200
become unit

0 commit comments

Comments
 (0)