Skip to content

Commit c1fcae8

Browse files
committed
chore: formatted arkscript code
1 parent 196bfdd commit c1fcae8

File tree

10 files changed

+86
-91
lines changed

10 files changed

+86
-91
lines changed

Benchmark.ark

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
# @author https://github.com/SuperFola
55
(macro measureOnce (tag code) {
66
(mut _start (time))
7-
{ code }
7+
{
8+
code }
89
(print (format "{} took {:.4} ms" tag (* 1000 (- (time) _start)))) })
910

1011
(import std.List)
@@ -29,7 +30,8 @@
2930
(mut _data [])
3031
(while (< _i times) {
3132
(let _start (time))
32-
{ ($as-is code) }
33+
{
34+
($as-is code) }
3335
(let _end (time))
3436
(append! _data (* 1000 (- _end _start)))
3537
(set _i (+ 1 _i)) })
@@ -41,4 +43,9 @@
4143
(print
4244
(format
4345
"{}, {} times\n ↪︎ range: [{:.3} - {:.3}] ms\n ↪︎ mean: {:.3}ms\n ↪︎ median: {:.3}ms"
44-
($repr code) times _min _max _mean _median)) })
46+
($repr code)
47+
times
48+
_min
49+
_max
50+
_mean
51+
_median)) })

Cli.ark

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,12 @@
66
(let required (= kind "value"))
77
(let value default)
88

9-
(fun (&kind
10-
&name
11-
&desc
12-
&default
13-
&value
14-
&required) ()) }))
9+
(fun (&kind &name &desc &default &value &required) ()) }))
1510

1611
(let _group (fun (children all_of) {
1712
(let kind "group")
1813

19-
(fun (&kind
20-
&children
21-
&all_of) ()) }))
14+
(fun (&kind &children &all_of) ()) }))
2215

2316
# @brief Defines a command line flag
2417
# @details All flags are optional and turned off
@@ -53,11 +46,11 @@
5346
(let e (@ partially_fmt i))
5447
(if (= (type e) "String")
5548
(set options (map
56-
options
57-
(fun (alt)
58-
(if (empty? alt)
59-
e
60-
(format "{} {}" alt e)))))
49+
options
50+
(fun (alt)
51+
(if (empty? alt)
52+
e
53+
(format "{} {}" alt e)))))
6154
# if we have a list, add (@ options 0) to each element of the list, then added to options
6255
(concat! options (map e (fun (alt) (format "{} {}" (@ options 0) alt)))))
6356
(set i (+ 1 i)) })
@@ -95,16 +88,16 @@
9588
(let params (dict))
9689
(_get_options params cli)
9790
(let options (join
98-
(map
99-
(dict:keys params)
100-
(fun (name) {
101-
(let param (dict:get params name))
102-
(let fmt_name
103-
(if (= param.kind "value")
104-
(format "<{}>" name)
105-
name))
106-
(format "\t{:<28} {}" fmt_name param.desc) }))
107-
"\n"))
91+
(map
92+
(dict:keys params)
93+
(fun (name) {
94+
(let param (dict:get params name))
95+
(let fmt_name
96+
(if (= param.kind "value")
97+
(format "<{}>" name)
98+
name))
99+
(format "\t{:<28} {}" fmt_name param.desc) }))
100+
"\n"))
108101

109102
(+ headers synopsis "\n\nOPTIONS\n" options) }))
110103

Events.ark

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@
4848
(list:forEach
4949
_listeners
5050
(fun (element)
51-
(if (= typ (@ element 0)) {
52-
((@ element 1) val)
53-
(set found true) })))
51+
(if (= typ (@ element 0))
52+
{
53+
((@ element 1) val)
54+
(set found true) })))
5455
found }))
5556

5657
# @brief Emits an event with no value

Lazy.ark

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
(mut _has_been_called false)
1313
(mut _memorized_value nil)
1414

15-
(fun (&f
16-
&_has_been_called
17-
&_memorized_value) {
18-
(if (not _has_been_called) {
19-
(set _has_been_called true)
20-
(set _memorized_value (f)) })
15+
(fun (&f &_has_been_called &_memorized_value) {
16+
(if (not _has_been_called)
17+
{
18+
(set _has_been_called true)
19+
(set _memorized_value (f)) })
2120
_memorized_value }) }))

List.ark

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@
127127
(if (= (_func _index _element) stopIteration)
128128
{
129129
(set _index (len _L))
130-
(set _early true)
131-
})
130+
(set _early true) })
131+
132132
(set _index (+ 1 _index)) })
133133

134134
_early }))
@@ -641,9 +641,10 @@
641641
(mut _i 0)
642642
(while (< _i _source_len) {
643643
(append! _current (@ _L _i))
644-
(if (= (len _current) _length) {
645-
(append! _output _current)
646-
(set _current []) })
644+
(if (= (len _current) _length)
645+
{
646+
(append! _output _current)
647+
(set _current []) })
647648
(set _i (+ 1 _i)) })
648649

649650
(if (not (empty? _current)) (append! _output _current))
@@ -710,8 +711,7 @@
710711
(if (= (_f _win) stopIteration)
711712
{
712713
(set _i (len _L))
713-
(set _early true)
714-
})
714+
(set _early true) })
715715

716716
(if (>= (+ _i _size) (len _L))
717717
(set _i (len _L)))
@@ -757,8 +757,7 @@
757757
(mut _i 0)
758758
(while (< _i (len _L)) {
759759
(let v (@ _L _i))
760-
(if (not (builtin__dict:contains _vals v))
761-
(builtin__dict:add _vals v _i))
760+
(if (not (builtin__dict:contains _vals v)) (builtin__dict:add _vals v _i))
762761
(set _i (+ 1 _i)) })
763762

764763
(builtin__dict:keys _vals) }))

Macros.ark

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,3 @@
132132
(macro unpackPair (pair outx outy) {
133133
(let outx ($as-is (@ pair 0)))
134134
(let outy ($as-is (@ pair 1))) })
135-

Math.ark

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,7 @@
324324
# =end
325325
# @author https://github.com/SuperFola
326326
(let complex (fun (real imag)
327-
(fun (&real
328-
&imag) ())))
327+
(fun (&real &imag) ())))
329328

330329
# @brief Compute the addition of two complex number
331330
# @param _c0 the first complex number
@@ -440,5 +439,4 @@
440439
# # 'base' is 27%~ slower than 'new'
441440
# =end
442441
# @author https://github.com/SuperFola
443-
(let improvementRatioPercentage (fun (_a _b)
444-
(* 100 (- (/ _a _b) 1))))
442+
(let improvementRatioPercentage (fun (_a _b) (* 100 (- (/ _a _b) 1))))

Range.ark

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@
2828
(let reset (fun ()
2929
(set i _a)))
3030

31-
(fun (&i
32-
&_a
33-
&_b
34-
&asList
35-
&reset) {
36-
(if (< i _b) {
37-
(set i (+ i 1))
38-
(- i 1) }) }) }))
31+
(fun (&i &_a &_b &asList &reset) {
32+
(if (< i _b)
33+
{
34+
(set i (+ i 1))
35+
(- i 1) }) }) }))
3936

4037
# @brief Run a function on each element of the range
4138
# @param _r the range object

String.ark

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# @brief Upper and lowercase ASCII letters
22
# @author https://github.com/SuperFola
3-
(let asciiLetters
4-
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
3+
(let asciiLetters "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
54

65
# @brief Lowercase ASCII letters
76
# @author https://github.com/SuperFola
@@ -25,13 +24,11 @@
2524

2625
# @brief All printable characters
2726
# @author https://github.com/SuperFola
28-
(let printable
29-
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r")
27+
(let printable "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r")
3028

3129
# @brief Punctuation characters
3230
# @author https://github.com/SuperFola
33-
(let punctuation
34-
"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~")
31+
(let punctuation "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~")
3532

3633
# @brief Whitespace characters
3734
# @author https://github.com/SuperFola
@@ -104,8 +101,7 @@
104101
# @param _str String where the lookup occurs
105102
# @param _word Word to look up for
106103
# @author https://github.com/SuperFola
107-
(let contains? (fun (_str _word)
108-
(!= -1 (find _str _word))))
104+
(let contains? (fun (_str _word) (!= -1 (find _str _word))))
109105

110106
# @brief Check if a string contains a word for a set of words
111107
# @param _str String where the lookup occurs
@@ -141,9 +137,10 @@
141137
(let _len (len _str))
142138
(while (< _i _len) {
143139
(let _c (@ _str _i))
144-
(if (and (!= _c " ") (!= _c "\t") (!= _c "\n") (!= _c "\r")) {
145-
(set _all_spaces false)
146-
(set _i _len) })
140+
(if (and (!= _c " ") (!= _c "\t") (!= _c "\n") (!= _c "\r"))
141+
{
142+
(set _all_spaces false)
143+
(set _i _len) })
147144
(set _i (+ 1 _i)) })
148145
_all_spaces })))
149146

@@ -258,7 +255,9 @@
258255
(if (= _length 0)
259256
""
260257
{
261-
(assert (and (>= _startingIndex 0) (< _startingIndex (len _string))) "slice start index must be in range [0, string length[")
258+
(assert
259+
(and (>= _startingIndex 0) (< _startingIndex (len _string)))
260+
"slice start index must be in range [0, string length[")
262261

263262
(mut _returnedString "")
264263
(mut _index _startingIndex)

Testing.ark

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,12 @@
197197
# (test:expect (return_true) "return true"})
198198
# =end
199199
# @author https://github.com/SuperFola
200-
(macro test:expect (_cond ..._desc) {{
201-
(set testing:_cond_res ($as-is _cond))
202-
(if (!= true testing:_cond_res)
203-
(testing:_report_error true testing:_cond_res "true" ($repr _cond) _desc)
204-
(testing:_report_success)) }})
200+
(macro test:expect (_cond ..._desc) {
201+
{
202+
(set testing:_cond_res ($as-is _cond))
203+
(if (!= true testing:_cond_res)
204+
(testing:_report_error true testing:_cond_res "true" ($repr _cond) _desc)
205+
(testing:_report_success)) } })
205206

206207
(mut _cond_res nil)
207208
(mut _expr_res nil)
@@ -219,12 +220,13 @@
219220
# (test:eq 5 (foo) "foo should return 5")})
220221
# =end
221222
# @author https://github.com/SuperFola
222-
(macro test:eq (_expr _expected ..._desc) {{
223-
(set testing:_expected_res ($as-is _expected))
224-
(set testing:_expr_res ($as-is _expr))
225-
(if (= testing:_expected_res testing:_expr_res)
226-
(testing:_report_success)
227-
(testing:_report_error testing:_expected_res testing:_expr_res ($repr _expected) ($repr _expr) _desc)) }})
223+
(macro test:eq (_expr _expected ..._desc) {
224+
{
225+
(set testing:_expected_res ($as-is _expected))
226+
(set testing:_expr_res ($as-is _expr))
227+
(if (= testing:_expected_res testing:_expr_res)
228+
(testing:_report_success)
229+
(testing:_report_error testing:_expected_res testing:_expr_res ($repr _expected) ($repr _expr) _desc)) } })
228230

229231
# @brief Compare two values that should **not** be equal and generate a test case
230232
# @param _value tested value
@@ -235,12 +237,13 @@
235237
# (test:neq 0 (my_function 1 2 3))})
236238
# =end
237239
# @author https://github.com/SuperFola
238-
(macro test:neq (_value _unexpected ..._desc) {{
239-
(set testing:_unexpected_res ($as-is _unexpected))
240-
(set testing:_value_res ($as-is _value))
241-
(if (!= testing:_unexpected_res testing:_value_res)
242-
(testing:_report_success)
243-
(testing:_report_error testing:_unexpected_res testing:_value_res ($repr _unexpected) ($repr _value) _desc)) }})
240+
(macro test:neq (_value _unexpected ..._desc) {
241+
{
242+
(set testing:_unexpected_res ($as-is _unexpected))
243+
(set testing:_value_res ($as-is _value))
244+
(if (!= testing:_unexpected_res testing:_value_res)
245+
(testing:_report_success)
246+
(testing:_report_error testing:_unexpected_res testing:_value_res ($repr _unexpected) ($repr _value) _desc)) } })
244247

245248
# @brief Generate the code for a test suite
246249
# @details Create two variables: _name-output (a list: [successes, failures]) and _name-status (boolean, true on success)
@@ -258,8 +261,8 @@
258261
(set testing:_suite (testing:_make_suite ($repr _name)))
259262

260263
(let ($symcat _name "-output") (testing:_runner
261-
($repr _name)
262-
(fun () ($as-is
263-
{
264-
_body }))))
264+
($repr _name)
265+
(fun () ($as-is
266+
{
267+
_body }))))
265268
(let ($symcat _name "-status") (= 0 (@ ($symcat _name "-output") 1))) })

0 commit comments

Comments
 (0)