|  | 
| 15 | 15 |     (while (< _index (len _L)) { | 
| 16 | 16 |         (mut _element (@ _L _index)) | 
| 17 | 17 |         (_func _element) | 
| 18 |  | -        (set _index (+ 1 _index)) | 
| 19 |  | -    }) | 
| 20 |  | -})) | 
|  | 18 | +        (set _index (+ 1 _index))})})) | 
| 21 | 19 | 
 | 
| 22 | 20 | # @brief Iterate over a given list and multiply all the elements with the others. | 
| 23 | 21 | # @param _L the list to iterate over | 
|  | 
| 33 | 31 |     (mut _output 1) | 
| 34 | 32 |     (while (< _index (len _L)) { | 
| 35 | 33 |         (set _output (* _output (@ _L _index))) | 
| 36 |  | -        (set _index (+ 1 _index)) | 
| 37 |  | -    }) | 
| 38 |  | -    _output | 
| 39 |  | -})) | 
|  | 34 | +        (set _index (+ 1 _index))}) | 
|  | 35 | +    _output })) | 
| 40 | 36 | 
 | 
| 41 | 37 | # @brief Iterate over a given list and sum all the elements. | 
| 42 | 38 | # @param _L the list to iterate over | 
|  | 
| 52 | 48 |     (mut _output 0) | 
| 53 | 49 |     (while (< _index (len _L)) { | 
| 54 | 50 |         (set _output (+ _output (@ _L _index))) | 
| 55 |  | -        (set _index (+ 1 _index)) | 
| 56 |  | -    }) | 
| 57 |  | -    _output | 
| 58 |  | -})) | 
|  | 51 | +        (set _index (+ 1 _index))}) | 
|  | 52 | +    _output })) | 
| 59 | 53 | 
 | 
| 60 | 54 | (import "Math.ark")  # needed for math:min, math:max | 
| 61 | 55 | 
 | 
|  | 
| 78 | 72 |             (mut _output []) | 
| 79 | 73 |             (while (< _index (len _L)) { | 
| 80 | 74 |                 (set _output (append _output (@ _L _index))) | 
| 81 |  | -                (set _index (+ 1 _index)) | 
| 82 |  | -            }) | 
| 83 |  | -            _output | 
| 84 |  | -        }))) | 
|  | 75 | +                (set _index (+ 1 _index))}) | 
|  | 76 | +            _output }))) | 
| 85 | 77 | 
 | 
| 86 | 78 | # @brief Drop the first elements of a list, while they match a given predicate | 
| 87 | 79 | # @param _L the list to work on | 
|  | 
| 101 | 93 | 
 | 
| 102 | 94 |             (while (< _index (len _L)) { | 
| 103 | 95 |                 (set _output (append _output (@ _L _index))) | 
| 104 |  | -                (set _index (+ 1 _index)) | 
| 105 |  | -            }))) | 
| 106 |  | -    _output | 
| 107 |  | -})) | 
|  | 96 | +                (set _index (+ 1 _index))}))) | 
|  | 97 | +    _output })) | 
| 108 | 98 | 
 | 
| 109 | 99 | # @brief Keep elements in a given list if they follow a predicate | 
| 110 | 100 | # @param _L the list to work on | 
|  | 
| 121 | 111 |     (while (< _index (len _L)) { | 
| 122 | 112 |         (if (_f (@ _L _index)) | 
| 123 | 113 |             (set _output (append _output (@ _L _index)))) | 
| 124 |  | -        (set _index (+ 1 _index)) | 
| 125 |  | -    }) | 
| 126 |  | -    _output | 
| 127 |  | -})) | 
|  | 114 | +        (set _index (+ 1 _index))}) | 
|  | 115 | +    _output })) | 
| 128 | 116 | 
 | 
| 129 | 117 | # @brief Apply a given function to each element of a list | 
| 130 | 118 | # @param _L the list to work on | 
|  | 
| 139 | 127 |     (mut _output []) | 
| 140 | 128 |     (while (< _index (len _L)) { | 
| 141 | 129 |         (set _output (append _output (_f (@ _L _index)))) | 
| 142 |  | -        (set _index (+ 1 _index)) | 
| 143 |  | -    }) | 
| 144 |  | -    _output | 
| 145 |  | -})) | 
|  | 130 | +        (set _index (+ 1 _index))}) | 
|  | 131 | +    _output })) | 
| 146 | 132 | 
 | 
| 147 | 133 | # @brief Apply a function to the elements of a list to reduce it | 
| 148 | 134 | # @param _L the list to work on | 
|  | 
| 158 | 144 |     (mut _output (@ _L 0)) | 
| 159 | 145 |     (while (< _index (len _L)) { | 
| 160 | 146 |         (set _output (_f _output (@ _L _index))) | 
| 161 |  | -        (set _index (+ 1 _index)) | 
| 162 |  | -    }) | 
| 163 |  | -    _output | 
| 164 |  | -})) | 
|  | 147 | +        (set _index (+ 1 _index))}) | 
|  | 148 | +    _output })) | 
| 165 | 149 | 
 | 
| 166 | 150 | # @brief Flatten a list | 
| 167 | 151 | # @param _L the list to work on | 
|  | 
| 179 | 163 |         (set _output (if (= "List" (type _sub)) | 
| 180 | 164 |             (concat _output _sub) | 
| 181 | 165 |             (append _output _sub))) | 
| 182 |  | -        (set _index (+ 1 _index)) | 
| 183 |  | -    }) | 
| 184 |  | -    _output | 
| 185 |  | -})) | 
|  | 166 | +        (set _index (+ 1 _index))}) | 
|  | 167 | +    _output })) | 
| 186 | 168 | 
 | 
| 187 | 169 | # @brief Apply a given function to each element of a list and then flatten it | 
| 188 | 170 | # @param _L the list to work on | 
|  | 
| 201 | 183 |         (set _output (if (= "List" (type _res)) | 
| 202 | 184 |             (concat _output _res) | 
| 203 | 185 |             (append _output _res))) | 
| 204 |  | -        (set _index (+ 1 _index)) | 
| 205 |  | -    }) | 
| 206 |  | -    _output | 
| 207 |  | -})) | 
|  | 186 | +        (set _index (+ 1 _index))}) | 
|  | 187 | +    _output })) | 
| 208 | 188 | 
 | 
| 209 | 189 | # @brief Take the first n elements of | 
| 210 | 190 | # @param _L the list to work on | 
|  | 
| 221 | 201 | 
 | 
| 222 | 202 |     (while (< _index _n) { | 
| 223 | 203 |         (set _output (append _output (@ _L _index))) | 
| 224 |  | -        (set _index (+ 1 _index)) | 
| 225 |  | -    }) | 
| 226 |  | -    _output | 
| 227 |  | -})) | 
|  | 204 | +        (set _index (+ 1 _index))}) | 
|  | 205 | +    _output })) | 
| 228 | 206 | 
 | 
| 229 | 207 | # @brief Take the first n elements of a list, given a predicate | 
| 230 | 208 | # @param _L the list to work on | 
|  | 
| 242 | 220 |         (if (_f (@ _L _index)) | 
| 243 | 221 |             { | 
| 244 | 222 |                 (set _output (append _output (@ _L _index))) | 
| 245 |  | -                (set _index (+ 1 _index)) | 
| 246 |  | -            } | 
| 247 |  | -            (set continue false) | 
| 248 |  | -        ) | 
| 249 |  | -    ) | 
| 250 |  | -    _output | 
| 251 |  | -})) | 
|  | 223 | +                (set _index (+ 1 _index))} | 
|  | 224 | +            (set continue false))) | 
|  | 225 | +    _output })) | 
| 252 | 226 | 
 | 
| 253 | 227 | # @brief Unzip a list of [[a b] [c d]...] into [[a c ...] [b d ...]] | 
| 254 | 228 | # @param _L the list to work on | 
|  | 
| 267 | 241 |         (mut current (@ _L _index)) | 
| 268 | 242 |         (set _list1 (append _list1 (@ current 0))) | 
| 269 | 243 |         (set _list2 (append _list2 (@ current 1))) | 
| 270 |  | -        (set _index (+ 1 _index)) | 
| 271 |  | -    }) | 
| 272 |  | -    [_list1 _list2] | 
| 273 |  | -})) | 
|  | 244 | +        (set _index (+ 1 _index))}) | 
|  | 245 | +    [_list1 _list2] })) | 
| 274 | 246 | 
 | 
| 275 | 247 | # @brief Zip two lists into one: [1 2 3 4] and [5 6 7 8] will give [[1 5] [2 6] [3 7] [4 8]] | 
| 276 | 248 | # @param _a the first list to work on | 
|  | 
| 288 | 260 |     (mut _index 0) | 
| 289 | 261 |     (while (< _index _m) { | 
| 290 | 262 |         (set _c (append _c [(@ _a _index) (@ _b _index)])) | 
| 291 |  | -        (set _index (+ 1 _index)) | 
| 292 |  | -    }) | 
| 293 |  | -    _c | 
| 294 |  | -})) | 
|  | 263 | +        (set _index (+ 1 _index))}) | 
|  | 264 | +    _c })) | 
| 295 | 265 | 
 | 
| 296 | 266 | # @brief Fold a given list, starting from the left side | 
| 297 | 267 | # @param _L the list to work on | 
|  | 
| 308 | 278 |     (mut _val _init) | 
| 309 | 279 |     (while (< _index (len _L)) { | 
| 310 | 280 |         (set _val (_f _val (@ _L _index))) | 
| 311 |  | -        (set _index (+ 1 _index)) | 
| 312 |  | -    }) | 
| 313 |  | -    _val | 
| 314 |  | -})) | 
|  | 281 | +        (set _index (+ 1 _index))}) | 
|  | 282 | +    _val })) | 
| 315 | 283 | 
 | 
| 316 | 284 | # @brief Check if a condition is verified for all elements of a list | 
| 317 | 285 | # @param _L the list to work on | 
|  | 
| 328 | 296 |     (while (and _verified (< _index (len _L))) { | 
| 329 | 297 |         (if (not (_f (@ _L _index))) | 
| 330 | 298 |             (set _verified false)) | 
| 331 |  | -        (set _index (+ 1 _index)) | 
| 332 |  | -    }) | 
| 333 |  | -    _verified | 
| 334 |  | -})) | 
|  | 299 | +        (set _index (+ 1 _index))}) | 
|  | 300 | +    _verified })) | 
| 335 | 301 | 
 | 
| 336 | 302 | # @brief Check if a condition if verified for one or more elements of a list | 
| 337 | 303 | # @param _L the list to work on | 
|  | 
| 348 | 314 |     (while (and (not _verified) (< _index (len _L))) { | 
| 349 | 315 |         (if (_f (@ _L _index)) | 
| 350 | 316 |             (set _verified true)) | 
| 351 |  | -        (set _index (+ 1 _index)) | 
| 352 |  | -    }) | 
| 353 |  | -    _verified | 
| 354 |  | -})) | 
|  | 317 | +        (set _index (+ 1 _index))}) | 
|  | 318 | +    _verified })) | 
0 commit comments