@@ -184,59 +184,59 @@ see the implementation of set `intersection` in this library.
184
184
` head ` returns the first element of the array:
185
185
186
186
``` fortran
187
- print *, head([1,2, 3])
187
+ print *, head([1, 2, 3])
188
188
1
189
189
```
190
190
191
191
` tail ` returns everything but the first element of the array:
192
192
193
193
``` fortran
194
- print *, tail([1,2, 3])
194
+ print *, tail([1, 2, 3])
195
195
2 3
196
196
```
197
197
198
198
Similarly, ` last ` returns the last element of the array:
199
199
200
200
``` fortran
201
- print *, last([1,2, 3])
201
+ print *, last([1, 2, 3])
202
202
3
203
203
```
204
204
205
205
` init ` returns everything but the last element of the array:
206
206
207
207
``` fortran
208
- print *, init([1,2, 3])
208
+ print *, init([1, 2, 3])
209
209
1 2
210
210
```
211
211
212
212
Subscript an array at specific indices:
213
213
214
214
``` fortran
215
- print *, subscript([1,2,3,4, 5], [3,4])
215
+ print *, subscript([1, 2, 3, 4, 5], [3, 4])
216
216
3 4
217
217
```
218
218
219
219
Unlike the Fortran 2008 vector subscript, the ` subscript ` function is out-of-bounds safe,
220
220
i.e. subscripting out of bounds returns an empty array:
221
221
222
222
``` fortran
223
- print *, subscript([1,2, 3], [10])
223
+ print *, subscript([1, 2, 3], [10])
224
224
225
225
```
226
226
227
227
We can prepend, append, or insert an element into an array using ` insert ` :
228
228
229
229
``` fortran
230
230
! insert a 5 at position 0 to prepend:
231
- print *, insert(5, 0, [1,2, 3])
231
+ print *, insert(5, 0, [1, 2, 3])
232
232
5 1 2 3
233
233
234
234
! insert a 5 at position 4 to append:
235
- print *, insert(5, 4, [1,2, 3])
235
+ print *, insert(5, 4, [1, 2, 3])
236
236
1 2 3 5
237
237
238
238
! insert a 2 at position 2:
239
- print *, insert(2, 2, [1,3, 4])
239
+ print *, insert(2, 2, [1, 3, 4])
240
240
1 2 3 4
241
241
```
242
242
@@ -307,7 +307,7 @@ pure recursive integer function fibonacci(n) result(fib)
307
307
end if
308
308
end function fibonacci
309
309
310
- print *, map(fibonacci, [17,5, 13,22])
310
+ print *, map(fibonacci, [17, 5, 13, 22])
311
311
1597 5 233 17711
312
312
```
313
313
@@ -321,13 +321,13 @@ pure logical function even(x)
321
321
even = mod(x, 2) == 0
322
322
endfunction even
323
323
324
- print *, filter(even,[1,2,3,4, 5])
324
+ print *, filter(even, [1, 2, 3, 4, 5])
325
325
2 4
326
326
```
327
327
Functions can be chained together into pretty one-liners:
328
328
329
329
``` fortran
330
- print *, filter(even,map(fibonacci,arange(1,10)))
330
+ print *, filter(even, map(fibonacci, arange(1, 10)))
331
331
2 8 34
332
332
```
333
333
@@ -354,11 +354,11 @@ input using the above-defined functions and a start value
354
354
355
355
``` fortran
356
356
! left-fold an array using add to compute array sum
357
- print *, foldl(add,0.,arange(1.,5.))
357
+ print *, foldl(add, 0., arange(1., 5.))
358
358
15.0000000
359
359
360
360
! left-fold an array using mult to compute array product
361
- print *, foldl(mult,1.,arange(1.,5.))
361
+ print *, foldl(mult, 1., arange(1., 5.))
362
362
120.000000
363
363
```
364
364
The above is a trivial example that re-invents Fortran intrinsics
@@ -381,7 +381,7 @@ pure real function multpt1(x)
381
381
multpt1 = 1.1 * x
382
382
endfunction multpt1
383
383
384
- write(*,*) unfold(multpt1,[1.],5)
384
+ write(*,*) unfold(multpt1, [1.], 5)
385
385
1.00000000 1.10000002 1.21000004 1.33100009 1.46410012
386
386
```
387
387
@@ -390,23 +390,23 @@ write(*,*) unfold(multpt1,[1.],5)
390
390
Function ` set ` returns all unique elements of an input array:
391
391
392
392
``` fortran
393
- print *, set([1,1,2,2, 3])
393
+ print *, set([1, 1, 2, 2, 3])
394
394
1 2 3
395
395
```
396
396
Common functions that operate on sets, ` union ` ,
397
397
` intersection ` , and ` complement ` , are also available:
398
398
399
399
``` fortran
400
400
! unique elements that are found in either array
401
- print *, union([1,2, 2],[2,3,3, 4])
401
+ print *, union([1, 2, 2], [2, 3, 3, 4])
402
402
1 2 3 4
403
403
404
404
! unique elements that are found in both arrays
405
- print *, intersection([1,2, 2],[2,3,3, 4])
405
+ print *, intersection([1, 2, 2], [2, 3, 3, 4])
406
406
2
407
407
408
408
! unique elements that are found first but not in second array
409
- print *, complement([1,2, 2],[2,3,3, 4])
409
+ print *, complement([1, 2, 2], [2, 3, 3, 4])
410
410
1
411
411
```
412
412
0 commit comments