Skip to content

Commit 96fc573

Browse files
authored
Merge pull request #7463 from smores56/auto-snake-case
Move builtins to snake_case
2 parents 83c78b0 + 68e82b8 commit 96fc573

File tree

398 files changed

+18022
-12349
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

398 files changed

+18022
-12349
lines changed

crates/cli/tests/benchmarks/AStar.roc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ initial_model = \start -> {
2323
cheapest_open : (position -> F64), Model position -> Result position {} where position implements Hash & Eq
2424
cheapest_open = \cost_fn, model ->
2525
model.open_set
26-
|> Set.toList
27-
|> List.keepOks(
26+
|> Set.to_list
27+
|> List.keep_oks(
2828
\position ->
2929
when Dict.get(model.costs, position) is
3030
Err(_) -> Err({})
@@ -33,7 +33,7 @@ cheapest_open = \cost_fn, model ->
3333
|> Quicksort.sort_by(.cost)
3434
|> List.first
3535
|> Result.map(.position)
36-
|> Result.mapErr(\_ -> {})
36+
|> Result.map_err(\_ -> {})
3737

3838
reconstruct_path : Dict position position, position -> List position where position implements Hash & Eq
3939
reconstruct_path = \came_from, goal ->
@@ -52,7 +52,7 @@ update_cost = \current, neighbor, model ->
5252
distance_to =
5353
reconstruct_path(new_came_from, neighbor)
5454
|> List.len
55-
|> Num.toFrac
55+
|> Num.to_frac
5656

5757
new_model =
5858
{ model &

crates/cli/tests/benchmarks/Base64.roc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ from_bytes = \bytes ->
1616
# base 64 encoding from a string
1717
from_str : Str -> Result Str [InvalidInput]
1818
from_str = \str ->
19-
from_bytes(Str.toUtf8(str))
19+
from_bytes(Str.to_utf8(str))
2020

2121
# base64-encode bytes to the original
2222
to_bytes : Str -> Result (List U8) [InvalidInput]
@@ -27,7 +27,7 @@ to_str : Str -> Result Str [InvalidInput]
2727
to_str = \str ->
2828
when to_bytes(str) is
2929
Ok(bytes) ->
30-
when Str.fromUtf8(bytes) is
30+
when Str.from_utf8(bytes) is
3131
Ok(v) ->
3232
Ok(v)
3333

crates/cli/tests/benchmarks/Base64/Decode.roc

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ loop_help = \{ remaining, string } ->
1414
if remaining >= 3 then
1515
Bytes.Decode.map3(Bytes.Decode.u8, Bytes.Decode.u8, Bytes.Decode.u8, \x, y, z ->
1616
a : U32
17-
a = Num.intCast(x)
17+
a = Num.int_cast(x)
1818
b : U32
19-
b = Num.intCast(y)
19+
b = Num.int_cast(y)
2020
c : U32
21-
c = Num.intCast(z)
22-
combined = Num.bitwiseOr(Num.bitwiseOr(Num.shiftLeftBy(a, 16), Num.shiftLeftBy(b, 8)), c)
21+
c = Num.int_cast(z)
22+
combined = Num.bitwise_or(Num.bitwise_or(Num.shift_left_by(a, 16), Num.shift_left_by(b, 8)), c)
2323

2424
Loop({
2525
remaining: remaining - 3,
@@ -31,24 +31,24 @@ loop_help = \{ remaining, string } ->
3131
Bytes.Decode.map2(Bytes.Decode.u8, Bytes.Decode.u8, \x, y ->
3232

3333
a : U32
34-
a = Num.intCast(x)
34+
a = Num.int_cast(x)
3535
b : U32
36-
b = Num.intCast(y)
37-
combined = Num.bitwiseOr(Num.shiftLeftBy(a, 16), Num.shiftLeftBy(b, 8))
36+
b = Num.int_cast(y)
37+
combined = Num.bitwise_or(Num.shift_left_by(a, 16), Num.shift_left_by(b, 8))
3838

3939
Done(Str.concat(string, bits_to_chars(combined, 1))))
4040
else
4141
# remaining = 1
4242
Bytes.Decode.map(Bytes.Decode.u8, \x ->
4343

4444
a : U32
45-
a = Num.intCast(x)
45+
a = Num.int_cast(x)
4646

47-
Done(Str.concat(string, bits_to_chars(Num.shiftLeftBy(a, 16), 2))))
47+
Done(Str.concat(string, bits_to_chars(Num.shift_left_by(a, 16), 2))))
4848

4949
bits_to_chars : U32, Int * -> Str
5050
bits_to_chars = \bits, missing ->
51-
when Str.fromUtf8(bits_to_chars_help(bits, missing)) is
51+
when Str.from_utf8(bits_to_chars_help(bits, missing)) is
5252
Ok(str) -> str
5353
Err(_) -> ""
5454

@@ -63,23 +63,23 @@ bits_to_chars_help = \bits, missing ->
6363
# with `0b111111` (which is 2^6 - 1 or 63) (so, 6 1s) to remove unwanted bits on the left.
6464
# any 6-bit number is a valid base64 digit, so this is actually safe
6565
p =
66-
Num.shiftRightZfBy(bits, 18)
67-
|> Num.intCast
66+
Num.shift_right_zf_by(bits, 18)
67+
|> Num.int_cast
6868
|> unsafe_to_char
6969

7070
q =
71-
Num.bitwiseAnd(Num.shiftRightZfBy(bits, 12), lowest6_bits_mask)
72-
|> Num.intCast
71+
Num.bitwise_and(Num.shift_right_zf_by(bits, 12), lowest6_bits_mask)
72+
|> Num.int_cast
7373
|> unsafe_to_char
7474

7575
r =
76-
Num.bitwiseAnd(Num.shiftRightZfBy(bits, 6), lowest6_bits_mask)
77-
|> Num.intCast
76+
Num.bitwise_and(Num.shift_right_zf_by(bits, 6), lowest6_bits_mask)
77+
|> Num.int_cast
7878
|> unsafe_to_char
7979

8080
s =
81-
Num.bitwiseAnd(bits, lowest6_bits_mask)
82-
|> Num.intCast
81+
Num.bitwise_and(bits, lowest6_bits_mask)
82+
|> Num.int_cast
8383
|> unsafe_to_char
8484

8585
equals : U8

crates/cli/tests/benchmarks/Base64/Encode.roc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ InvalidChar : U8
88
to_bytes : Str -> List U8
99
to_bytes = \str ->
1010
str
11-
|> Str.toUtf8
11+
|> Str.to_utf8
1212
|> encode_chunks
1313
|> Bytes.Encode.sequence
1414
|> Bytes.Encode.encode
@@ -73,18 +73,18 @@ encode_characters = \a, b, c, d ->
7373
n2 = unsafe_convert_char(b)
7474

7575
x : U32
76-
x = Num.intCast(n1)
76+
x = Num.int_cast(n1)
7777

7878
y : U32
79-
y = Num.intCast(n2)
79+
y = Num.int_cast(n2)
8080

8181
if d == equals then
8282
if c == equals then
83-
n = Num.bitwiseOr(Num.shiftLeftBy(x, 18), Num.shiftLeftBy(y, 12))
83+
n = Num.bitwise_or(Num.shift_left_by(x, 18), Num.shift_left_by(y, 12))
8484

8585
# masking higher bits is not needed, Encode.unsignedInt8 ignores higher bits
8686
b1 : U8
87-
b1 = Num.intCast(Num.shiftRightBy(n, 16))
87+
b1 = Num.int_cast(Num.shift_right_by(n, 16))
8888

8989
Ok(Bytes.Encode.u8(b1))
9090
else if !(is_valid_char(c)) then
@@ -93,12 +93,12 @@ encode_characters = \a, b, c, d ->
9393
n3 = unsafe_convert_char(c)
9494

9595
z : U32
96-
z = Num.intCast(n3)
96+
z = Num.int_cast(n3)
9797

98-
n = Num.bitwiseOr(Num.bitwiseOr(Num.shiftLeftBy(x, 18), Num.shiftLeftBy(y, 12)), Num.shiftLeftBy(z, 6))
98+
n = Num.bitwise_or(Num.bitwise_or(Num.shift_left_by(x, 18), Num.shift_left_by(y, 12)), Num.shift_left_by(z, 6))
9999

100100
combined : U16
101-
combined = Num.intCast(Num.shiftRightBy(n, 8))
101+
combined = Num.int_cast(Num.shift_right_by(n, 8))
102102

103103
Ok(Bytes.Encode.u16(BE, combined))
104104
else if !(is_valid_char(d)) then
@@ -108,22 +108,22 @@ encode_characters = \a, b, c, d ->
108108
n4 = unsafe_convert_char(d)
109109

110110
z : U32
111-
z = Num.intCast(n3)
111+
z = Num.int_cast(n3)
112112

113113
w : U32
114-
w = Num.intCast(n4)
114+
w = Num.int_cast(n4)
115115

116116
n =
117-
Num.bitwiseOr(
118-
Num.bitwiseOr(Num.shiftLeftBy(x, 18), Num.shiftLeftBy(y, 12)),
119-
Num.bitwiseOr(Num.shiftLeftBy(z, 6), w),
117+
Num.bitwise_or(
118+
Num.bitwise_or(Num.shift_left_by(x, 18), Num.shift_left_by(y, 12)),
119+
Num.bitwise_or(Num.shift_left_by(z, 6), w),
120120
)
121121

122122
b3 : U8
123-
b3 = Num.intCast(n)
123+
b3 = Num.int_cast(n)
124124

125125
combined : U16
126-
combined = Num.intCast(Num.shiftRightBy(n, 8))
126+
combined = Num.int_cast(Num.shift_right_by(n, 8))
127127

128128
Ok(Bytes.Encode.sequence([Bytes.Encode.u16(BE, combined), Bytes.Encode.u8(b3)]))
129129

crates/cli/tests/benchmarks/Bytes/Decode.roc

Lines changed: 71 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -7,105 +7,111 @@ DecodeProblem : [OutOfBytes]
77
ByteDecoder a := State -> [Good State a, Bad DecodeProblem]
88

99
decode : List U8, ByteDecoder a -> Result a DecodeProblem
10-
decode = \bytes, @ByteDecoder decoder ->
11-
when decoder { bytes, cursor: 0 } is
12-
Good _ value ->
13-
Ok value
10+
decode = \bytes, @ByteDecoder(decoder) ->
11+
when decoder({ bytes, cursor: 0 }) is
12+
Good(_, value) ->
13+
Ok(value)
1414

15-
Bad e ->
16-
Err e
15+
Bad(e) ->
16+
Err(e)
1717

1818
succeed : a -> ByteDecoder a
19-
succeed = \value -> @ByteDecoder \state -> Good state value
19+
succeed = \value -> @ByteDecoder(\state -> Good(state, value))
2020

2121
map : ByteDecoder a, (a -> b) -> ByteDecoder b
22-
map = \@ByteDecoder decoder, transform ->
23-
@ByteDecoder
22+
map = \@ByteDecoder(decoder), transform ->
23+
@ByteDecoder(
2424
\state ->
25-
when decoder state is
26-
Good state1 value ->
27-
Good state1 (transform value)
25+
when decoder(state) is
26+
Good(state1, value) ->
27+
Good(state1, transform(value))
2828

29-
Bad e ->
30-
Bad e
29+
Bad(e) ->
30+
Bad(e),
31+
)
3132

3233
map2 : ByteDecoder a, ByteDecoder b, (a, b -> c) -> ByteDecoder c
33-
map2 = \@ByteDecoder decoder1, @ByteDecoder decoder2, transform ->
34-
@ByteDecoder
34+
map2 = \@ByteDecoder(decoder1), @ByteDecoder(decoder2), transform ->
35+
@ByteDecoder(
3536
\state1 ->
36-
when decoder1 state1 is
37-
Good state2 a ->
38-
when decoder2 state2 is
39-
Good state3 b ->
40-
Good state3 (transform a b)
37+
when decoder1(state1) is
38+
Good(state2, a) ->
39+
when decoder2(state2) is
40+
Good(state3, b) ->
41+
Good(state3, transform(a, b))
4142

42-
Bad e ->
43-
Bad e
43+
Bad(e) ->
44+
Bad(e)
4445

45-
Bad e ->
46-
Bad e
46+
Bad(e) ->
47+
Bad(e),
48+
)
4749

4850
map3 : ByteDecoder a, ByteDecoder b, ByteDecoder c, (a, b, c -> d) -> ByteDecoder d
49-
map3 = \@ByteDecoder decoder1, @ByteDecoder decoder2, @ByteDecoder decoder3, transform ->
50-
@ByteDecoder
51+
map3 = \@ByteDecoder(decoder1), @ByteDecoder(decoder2), @ByteDecoder(decoder3), transform ->
52+
@ByteDecoder(
5153
\state1 ->
52-
when decoder1 state1 is
53-
Good state2 a ->
54-
when decoder2 state2 is
55-
Good state3 b ->
56-
when decoder3 state3 is
57-
Good state4 c ->
58-
Good state4 (transform a b c)
54+
when decoder1(state1) is
55+
Good(state2, a) ->
56+
when decoder2(state2) is
57+
Good(state3, b) ->
58+
when decoder3(state3) is
59+
Good(state4, c) ->
60+
Good(state4, transform(a, b, c))
5961

60-
Bad e ->
61-
Bad e
62+
Bad(e) ->
63+
Bad(e)
6264

63-
Bad e ->
64-
Bad e
65+
Bad(e) ->
66+
Bad(e)
6567

66-
Bad e ->
67-
Bad e
68+
Bad(e) ->
69+
Bad(e),
70+
)
6871

6972
after : ByteDecoder a, (a -> ByteDecoder b) -> ByteDecoder b
70-
after = \@ByteDecoder decoder, transform ->
71-
@ByteDecoder
73+
after = \@ByteDecoder(decoder), transform ->
74+
@ByteDecoder(
7275
\state ->
73-
when decoder state is
74-
Good state1 value ->
75-
(@ByteDecoder decoder1) = transform value
76+
when decoder(state) is
77+
Good(state1, value) ->
78+
@ByteDecoder(decoder1) = transform(value)
7679

77-
decoder1 state1
80+
decoder1(state1)
7881

79-
Bad e ->
80-
Bad e
82+
Bad(e) ->
83+
Bad(e),
84+
)
8185

8286
u8 : ByteDecoder U8
83-
u8 = @ByteDecoder
87+
u8 = @ByteDecoder(
8488
\state ->
85-
when List.get state.bytes state.cursor is
86-
Ok b ->
87-
Good { state & cursor: state.cursor + 1 } b
89+
when List.get(state.bytes, state.cursor) is
90+
Ok(b) ->
91+
Good({ state & cursor: state.cursor + 1 }, b)
8892

89-
Err _ ->
90-
Bad OutOfBytes
93+
Err(_) ->
94+
Bad(OutOfBytes),
95+
)
9196

9297
Step state b : [Loop state, Done b]
9398

9499
loop : (state -> ByteDecoder (Step state a)), state -> ByteDecoder a
95100
loop = \stepper, initial ->
96-
@ByteDecoder
101+
@ByteDecoder(
97102
\state ->
98-
loopHelp stepper initial state
103+
loop_help(stepper, initial, state),
104+
)
99105

100-
loopHelp = \stepper, accum, state ->
101-
(@ByteDecoder stepper1) = stepper accum
106+
loop_help = \stepper, accum, state ->
107+
@ByteDecoder(stepper1) = stepper(accum)
102108

103-
when stepper1 state is
104-
Good newState (Done value) ->
105-
Good newState value
109+
when stepper1(state) is
110+
Good(new_state, Done(value)) ->
111+
Good(new_state, value)
106112

107-
Good newState (Loop newAccum) ->
108-
loopHelp stepper newAccum newState
113+
Good(new_state, Loop(new_accum)) ->
114+
loop_help(stepper, new_accum, new_state)
109115

110-
Bad e ->
111-
Bad e
116+
Bad(e) ->
117+
Bad(e)

0 commit comments

Comments
 (0)