Skip to content

Commit 00fa657

Browse files
Transform 0 arguments closure to direct function calls as recommended by Jose
1 parent c54ce5a commit 00fa657

5 files changed

Lines changed: 19 additions & 20 deletions

File tree

pact/contracts/util-lists.pact

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
(defun chain:list (in:list)
4848
"Chain list of lists"
49-
(fold (+) [] in))
49+
(fold + [] in))
5050

5151
(defun same-length:bool (x:list y:list)
5252
"Return true if two lists have the same length"
@@ -94,7 +94,7 @@
9494
(if (contains item in)
9595
(let ((indexes (enumerate 0 (length in)))
9696
(match (lambda (v i) (if (= item v) i -1))))
97-
(remove-item (zip (match) in indexes) -1))
97+
(remove-item (zip match in indexes) -1))
9898
[])
9999
)
100100

pact/contracts/util-math.pact

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@
4242
(defun min-list:decimal (x:[decimal])
4343
"Returns the min of a list"
4444
(enforce-not-empty x)
45-
(fold (min) (first x) (remove-first x))
45+
(fold min (first x) (remove-first x))
4646
)
4747

4848
(defun amin:integer (in:[decimal])
4949
"Returns the min index of a list"
5050
(enforce-not-empty in)
5151
(let ((in-enum (enumerate-list in))
5252
(cmp (lambda (x y) (if (< (at 'v x) (at 'v y)) x y))))
53-
(at 'i (fold (cmp) (first in-enum) (remove-first in-enum))))
53+
(at 'i (fold cmp (first in-enum) (remove-first in-enum))))
5454
)
5555

5656
(defun max:decimal (x:decimal y:decimal)
@@ -68,15 +68,15 @@
6868
(defun max-list:decimal (x:[decimal])
6969
"Returns the max of a list"
7070
(enforce-not-empty x)
71-
(fold (max) (first x) (remove-first x))
71+
(fold max (first x) (remove-first x))
7272
)
7373

7474
(defun amax:integer (in:[decimal])
7575
"Returns the max index of a list"
7676
(enforce-not-empty in)
7777
(let ((in-enum (enumerate-list in))
7878
(cmp (lambda (x y) (if (> (at 'v x) (at 'v y)) x y))))
79-
(at 'i (fold (cmp) (first in-enum) (remove-first in-enum))))
79+
(at 'i (fold cmp (first in-enum) (remove-first in-enum))))
8080
)
8181

8282
(defun clamp:decimal (low-limit:decimal up-limit:decimal x:decimal)
@@ -97,7 +97,7 @@
9797

9898
(defun sum:decimal (x:[decimal])
9999
"Returns the sum of a list"
100-
(fold (+) 0.0 x))
100+
(fold + 0.0 x))
101101

102102
(defun prod3:decimal (x:decimal y:decimal z:decimal)
103103
"Returns the product of 3 values"
@@ -109,7 +109,7 @@
109109

110110
(defun prod:decimal (x:[decimal])
111111
"Returns the product of a list"
112-
(fold (*) 1.0 x))
112+
(fold * 1.0 x))
113113

114114
(defun square:decimal (x:decimal)
115115
"Returns the square of x"
@@ -213,7 +213,7 @@
213213
(gcd-inner (lambda (x i) (if (= (at 'b x) 0)
214214
x
215215
{'a: (at 'b x), 'b: (mod (at 'a x) (at 'b x))})))
216-
(gcd-result (fold (gcd-inner) {'a:a*, 'b:b*} (enumerate 1 max-iterations))))
216+
(gcd-result (fold gcd-inner {'a:a*, 'b:b*} (enumerate 1 max-iterations))))
217217
(enforce (= (at 'b gcd-result) 0) "Euclidean algorithm not finished")
218218
(at 'a gcd-result))))
219219
)

pact/contracts/util-random.pact

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
(assign-order (lambda (x i) {'order:i, 'val:x })))
120120
(map (at 'val)
121121
(sort ['order]
122-
(zip (assign-order) in (map (hash) indexes)))))
122+
(zip assign-order in (map (hash) indexes)))))
123123
)
124124

125125
(defun gen-uuid-rfc-4122-v4:string ()

pact/contracts/util-strings.pact

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@
5555

5656
(defun str-to-ascii-int:integer (in:string)
5757
"Convert a string to its integer ASCII representation"
58-
(let ((shift-add (lambda (x y) (+ (shift x 8) y))))
59-
(fold (shift-add) 0 (decode-ascii in)))
58+
(fold (lambda (x y) (+ (shift x 8) y)) 0 (decode-ascii in))
6059
)
6160

6261
(defun encode-ascii:string (in-list:[integer])
@@ -72,7 +71,7 @@
7271
(if (!= in 0)
7372
(let ((len (ceiling (log 256.0 (dec in))))
7473
(extract-char-value (lambda (idx) (mod (shift in (* -8 idx)) 256))))
75-
(encode-ascii (map (extract-char-value) (enumerate (- len 1) 0))))
74+
(encode-ascii (map extract-char-value (enumerate (- len 1) 0))))
7675
"")
7776
)
7877

@@ -100,7 +99,7 @@
10099
"Returns true if in contains one of the characters in values"
101100
(let ((values-lists (str-to-list values))
102101
(contains-char (lambda (x) (contains x in))))
103-
(fold (or) false (map (contains-char) values-lists)))
102+
(fold (or) false (map contains-char values-lists)))
104103
)
105104

106105
(defun replace-char:string (in:string old-char:string new-char:string)
@@ -114,7 +113,7 @@
114113
(if (and? (<= 97) (>= 122) x)
115114
(- x 32)
116115
x))))
117-
(encode-ascii (map (do-upper) (decode-ascii in))))
116+
(encode-ascii (map do-upper (decode-ascii in))))
118117
)
119118

120119
(defun lower:string (in:string)
@@ -123,7 +122,7 @@
123122
(if (and? (<= 65) (>= 90) x)
124123
(+ x 32)
125124
x))))
126-
(encode-ascii (map (do-lower) (decode-ascii in))))
125+
(encode-ascii (map do-lower (decode-ascii in))))
127126
)
128127

129128
(defun char-at:string (idx:integer in:string)
@@ -151,9 +150,9 @@
151150
[] ;If the string is empty return a zero length list
152151
(let ((sep-pos (search (str-to-list in) separator))
153152
(substart (map (+ 1) (insert-first sep-pos -1)))
154-
(sublen (zip (-) (append-last sep-pos 10000000) substart))
153+
(sublen (zip - (append-last sep-pos 10000000) substart))
155154
(cut (lambda (start len) (take len (drop start in)))))
156-
(zip (cut) substart sublen)))
155+
(zip cut substart sublen)))
157156
)
158157

159158
(defun split-chunks:[string] (chunk-size:integer in:string)
@@ -164,7 +163,7 @@
164163
(take-chunk (lambda (x) (take chunk-size (drop (* x chunk-size) in)))))
165164
(if (= 0 out-len)
166165
[]
167-
(map (take-chunk) (enumerate 0 (- out-len 1)))))
166+
(map take-chunk (enumerate 0 (- out-len 1)))))
168167
)
169168

170169
(defun starts-with:bool (in:string to-match:string)

pact/contracts/util-zk.pact

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
(defun serialize-proof:string (proof:object{groth16-proof})
7474
"Serialiaze an object proof to its base64 representation (344 octets)"
7575
(bind proof {'A:=A, 'B:=B, 'C:=C}
76-
(concat (map (int256-to-b64) [ (at 'x A), (at 'y A),
76+
(concat (map int256-to-b64 [ (at 'x A), (at 'y A),
7777
(at 0 (at 'x B)), (at 1 (at 'x B)),
7878
(at 0 (at 'y B)), (at 1 (at 'y B)),
7979
(at 'x C), (at 'y C)

0 commit comments

Comments
 (0)