Skip to content

Commit 0ecb2d2

Browse files
committed
std: Fixed the stdlib
1 parent 3b78398 commit 0ecb2d2

File tree

5 files changed

+35
-33
lines changed

5 files changed

+35
-33
lines changed

std/args/args.pics

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Args :: module {
99
//
1010
// Example:
1111
// --- Code
12-
// let args = Args.get()
13-
// IO.println(Array.toString(args))
12+
// args := Args.get()
13+
// IO::println(Array::toString(args))
1414
// --- Code
1515
get :: () = _pic_nat_user_args
1616

std/array/array.pics

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ Array :: module {
8888
when xs {
8989
is [] -> []
9090
is x:rest ->
91-
if pred(x) {
91+
if pred(x) do {
9292
x : filter(rest, pred)
93-
} else {
93+
} else do {
9494
filter(rest, pred)
9595
}
9696
}
@@ -154,9 +154,9 @@ Array :: module {
154154
// Returns:
155155
// A new array with at most N elements
156156
take :: (xs=[], n=0) =
157-
if n <= 0 {
157+
if n <= 0 do {
158158
[]
159-
} else {
159+
} else do {
160160
when xs {
161161
is [] -> []
162162
is x:rest -> x : take(rest, n - 1)
@@ -173,9 +173,9 @@ Array :: module {
173173
// Returns:
174174
// A new array without the first N elements
175175
drop :: (xs=[], n=0) =
176-
if n <= 0 {
176+
if n <= 0 do {
177177
xs
178-
} else {
178+
} else do {
179179
when xs {
180180
is [] -> []
181181
is _:rest -> drop(rest, n - 1)
@@ -194,7 +194,7 @@ Array :: module {
194194
contains :: (xs=[], value) =
195195
when xs {
196196
is [] -> false
197-
is x:rest -> if x == value { true } else { contains(rest, value) }
197+
is x:rest -> if x == value do { true } else do { contains(rest, value) }
198198
}
199199

200200
// Function: indexOf
@@ -210,7 +210,7 @@ Array :: module {
210210
indexOf :: (xs=[], value, i=0) =
211211
when xs {
212212
is [] -> -1
213-
is x:rest -> if x == value { i } else { indexOf(rest, value, i + 1) }
213+
is x:rest -> if x == value do { i } else do { indexOf(rest, value, i + 1) }
214214
}
215215

216216
// Function: fromRange
@@ -223,12 +223,12 @@ Array :: module {
223223
// Returns:
224224
// An array representing the range [start, ..., end]
225225
fromRange :: (start, end) =
226-
if start == end {
226+
if start == end do {
227227
[end]
228-
} else {
229-
if start < end {
228+
} else do {
229+
if start < end do {
230230
start : fromRange(start + 1, end)
231-
} else {
231+
} else do {
232232
start : fromRange(start - 1, end)
233233
}
234234
}

std/math/math.pics

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ Math :: module {
158158
// Returns:
159159
// The clamped value, either `a`, `low`, or `high`
160160
clamp :: (a=0, low=-1, high=1) =
161-
if a < low { low }
162-
else {
163-
if a > high { high }
164-
else { a }
161+
if a < low do { low }
162+
else do {
163+
if a > high do { high }
164+
else do { a }
165165
}
166166

167167

@@ -174,7 +174,7 @@ Math :: module {
174174
//
175175
// Returns:
176176
// The maximum between `a` and `b`
177-
max :: (a=0, b=0) = if a > b { a } else { b }
177+
max :: (a=0, b=0) = if a > b do { a } else do { b }
178178

179179

180180
// Function: min
@@ -186,7 +186,7 @@ Math :: module {
186186
//
187187
// Returns:
188188
// The minimum between `a` and `b`
189-
min :: (a=0, b=0) = if a < b { a } else { b }
189+
min :: (a=0, b=0) = if a < b do { a } else do { b }
190190

191191

192192
// Function: degToRad
@@ -220,8 +220,8 @@ Math :: module {
220220
// Returns:
221221
// The factorial of `n`
222222
factorial :: (n=0) =
223-
if n <= 1 { 1 }
224-
else { n * factorial(n - 1) }
223+
if n <= 1 do { 1 }
224+
else do { n * factorial(n - 1) }
225225

226226
// Variable: E
227227
// The double value that is closer than any other to e, the base of the natural logarithms.

std/number/number.pics

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@ Number :: module {
9191
// -1 if the number is negative,
9292
// 0 if the number is zero
9393
sign :: (n=0) =
94-
if n > 0 then 1
95-
else if n < 0 then -1
96-
else 0
94+
if n > 0 do { 1 }
95+
else do {
96+
if n < 0 do { -1 }
97+
else do { 0 }
98+
}
9799

98100
}
99101

std/string/string.pics

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ String :: module {
8383
// Returns:
8484
// A new string consisting of `str` repeated `n` times
8585
repeat :: (str="", n=0) =
86-
if n <= 0 { "" }
87-
else { str + repeat(str, n - 1) }
86+
if n <= 0 do { "" }
87+
else do { str + repeat(str, n - 1) }
8888

8989

9090
// Function: padLeft
@@ -98,9 +98,9 @@ String :: module {
9898
// Returns:
9999
// A new string padded on the left to reach `total` length
100100
padLeft :: (str="", total=0, char=" ") = do {
101-
let padCount = total - String::length(str)
102-
if padCount <= 0 { str }
103-
else { repeat(char, padCount) + str }
101+
padCount := total - String::length(str)
102+
if padCount <= 0 do { str }
103+
else do { repeat(char, padCount) + str }
104104
}
105105

106106

@@ -115,9 +115,9 @@ String :: module {
115115
// Returns:
116116
// A new string padded on the right to reach `total` length
117117
padRight :: (str="", total=0, char=" ") = do {
118-
let padCount = total - String::length(str)
119-
if padCount <= 0 { str }
120-
else { str + repeat(char, padCount) }
118+
padCount := total - String::length(str)
119+
if padCount <= 0 do { str }
120+
else do { str + repeat(char, padCount) }
121121
}
122122

123123
// Variable: EMPTY

0 commit comments

Comments
 (0)