From 1abdcdda0d2b3f48024b39592d530d458e63fac0 Mon Sep 17 00:00:00 2001 From: milancurcic Date: Thu, 19 Nov 2020 19:47:07 -0500 Subject: [PATCH 01/11] move source files to fpm default locations --- src/{lib => }/mod_functional.f90 | 0 src/{lib => }/mod_interfaces.f90 | 0 {src/tests => test}/mod_testing.f90 | 0 {src/tests => test}/test_arange.f90 | 0 {src/tests => test}/test_arrstr.f90 | 0 {src/tests => test}/test_complement.f90 | 0 {src/tests => test}/test_empty.f90 | 0 {src/tests => test}/test_filter.f90 | 0 {src/tests => test}/test_foldl.f90 | 0 {src/tests => test}/test_foldr.f90 | 0 {src/tests => test}/test_foldt.f90 | 0 {src/tests => test}/test_head.f90 | 0 {src/tests => test}/test_init.f90 | 0 {src/tests => test}/test_insert.f90 | 0 {src/tests => test}/test_intersection.f90 | 0 {src/tests => test}/test_iterfold.f90 | 0 {src/tests => test}/test_last.f90 | 0 {src/tests => test}/test_limit.f90 | 0 {src/tests => test}/test_map.f90 | 0 {src/tests => test}/test_reverse.f90 | 0 {src/tests => test}/test_set.f90 | 0 {src/tests => test}/test_sort.f90 | 0 {src/tests => test}/test_split.f90 | 0 {src/tests => test}/test_strarr.f90 | 0 {src/tests => test}/test_subscript.f90 | 0 {src/tests => test}/test_tail.f90 | 0 {src/tests => test}/test_unfold.f90 | 0 {src/tests => test}/test_union.f90 | 0 28 files changed, 0 insertions(+), 0 deletions(-) rename src/{lib => }/mod_functional.f90 (100%) rename src/{lib => }/mod_interfaces.f90 (100%) rename {src/tests => test}/mod_testing.f90 (100%) rename {src/tests => test}/test_arange.f90 (100%) rename {src/tests => test}/test_arrstr.f90 (100%) rename {src/tests => test}/test_complement.f90 (100%) rename {src/tests => test}/test_empty.f90 (100%) rename {src/tests => test}/test_filter.f90 (100%) rename {src/tests => test}/test_foldl.f90 (100%) rename {src/tests => test}/test_foldr.f90 (100%) rename {src/tests => test}/test_foldt.f90 (100%) rename {src/tests => test}/test_head.f90 (100%) rename {src/tests => test}/test_init.f90 (100%) rename {src/tests => test}/test_insert.f90 (100%) rename {src/tests => test}/test_intersection.f90 (100%) rename {src/tests => test}/test_iterfold.f90 (100%) rename {src/tests => test}/test_last.f90 (100%) rename {src/tests => test}/test_limit.f90 (100%) rename {src/tests => test}/test_map.f90 (100%) rename {src/tests => test}/test_reverse.f90 (100%) rename {src/tests => test}/test_set.f90 (100%) rename {src/tests => test}/test_sort.f90 (100%) rename {src/tests => test}/test_split.f90 (100%) rename {src/tests => test}/test_strarr.f90 (100%) rename {src/tests => test}/test_subscript.f90 (100%) rename {src/tests => test}/test_tail.f90 (100%) rename {src/tests => test}/test_unfold.f90 (100%) rename {src/tests => test}/test_union.f90 (100%) diff --git a/src/lib/mod_functional.f90 b/src/mod_functional.f90 similarity index 100% rename from src/lib/mod_functional.f90 rename to src/mod_functional.f90 diff --git a/src/lib/mod_interfaces.f90 b/src/mod_interfaces.f90 similarity index 100% rename from src/lib/mod_interfaces.f90 rename to src/mod_interfaces.f90 diff --git a/src/tests/mod_testing.f90 b/test/mod_testing.f90 similarity index 100% rename from src/tests/mod_testing.f90 rename to test/mod_testing.f90 diff --git a/src/tests/test_arange.f90 b/test/test_arange.f90 similarity index 100% rename from src/tests/test_arange.f90 rename to test/test_arange.f90 diff --git a/src/tests/test_arrstr.f90 b/test/test_arrstr.f90 similarity index 100% rename from src/tests/test_arrstr.f90 rename to test/test_arrstr.f90 diff --git a/src/tests/test_complement.f90 b/test/test_complement.f90 similarity index 100% rename from src/tests/test_complement.f90 rename to test/test_complement.f90 diff --git a/src/tests/test_empty.f90 b/test/test_empty.f90 similarity index 100% rename from src/tests/test_empty.f90 rename to test/test_empty.f90 diff --git a/src/tests/test_filter.f90 b/test/test_filter.f90 similarity index 100% rename from src/tests/test_filter.f90 rename to test/test_filter.f90 diff --git a/src/tests/test_foldl.f90 b/test/test_foldl.f90 similarity index 100% rename from src/tests/test_foldl.f90 rename to test/test_foldl.f90 diff --git a/src/tests/test_foldr.f90 b/test/test_foldr.f90 similarity index 100% rename from src/tests/test_foldr.f90 rename to test/test_foldr.f90 diff --git a/src/tests/test_foldt.f90 b/test/test_foldt.f90 similarity index 100% rename from src/tests/test_foldt.f90 rename to test/test_foldt.f90 diff --git a/src/tests/test_head.f90 b/test/test_head.f90 similarity index 100% rename from src/tests/test_head.f90 rename to test/test_head.f90 diff --git a/src/tests/test_init.f90 b/test/test_init.f90 similarity index 100% rename from src/tests/test_init.f90 rename to test/test_init.f90 diff --git a/src/tests/test_insert.f90 b/test/test_insert.f90 similarity index 100% rename from src/tests/test_insert.f90 rename to test/test_insert.f90 diff --git a/src/tests/test_intersection.f90 b/test/test_intersection.f90 similarity index 100% rename from src/tests/test_intersection.f90 rename to test/test_intersection.f90 diff --git a/src/tests/test_iterfold.f90 b/test/test_iterfold.f90 similarity index 100% rename from src/tests/test_iterfold.f90 rename to test/test_iterfold.f90 diff --git a/src/tests/test_last.f90 b/test/test_last.f90 similarity index 100% rename from src/tests/test_last.f90 rename to test/test_last.f90 diff --git a/src/tests/test_limit.f90 b/test/test_limit.f90 similarity index 100% rename from src/tests/test_limit.f90 rename to test/test_limit.f90 diff --git a/src/tests/test_map.f90 b/test/test_map.f90 similarity index 100% rename from src/tests/test_map.f90 rename to test/test_map.f90 diff --git a/src/tests/test_reverse.f90 b/test/test_reverse.f90 similarity index 100% rename from src/tests/test_reverse.f90 rename to test/test_reverse.f90 diff --git a/src/tests/test_set.f90 b/test/test_set.f90 similarity index 100% rename from src/tests/test_set.f90 rename to test/test_set.f90 diff --git a/src/tests/test_sort.f90 b/test/test_sort.f90 similarity index 100% rename from src/tests/test_sort.f90 rename to test/test_sort.f90 diff --git a/src/tests/test_split.f90 b/test/test_split.f90 similarity index 100% rename from src/tests/test_split.f90 rename to test/test_split.f90 diff --git a/src/tests/test_strarr.f90 b/test/test_strarr.f90 similarity index 100% rename from src/tests/test_strarr.f90 rename to test/test_strarr.f90 diff --git a/src/tests/test_subscript.f90 b/test/test_subscript.f90 similarity index 100% rename from src/tests/test_subscript.f90 rename to test/test_subscript.f90 diff --git a/src/tests/test_tail.f90 b/test/test_tail.f90 similarity index 100% rename from src/tests/test_tail.f90 rename to test/test_tail.f90 diff --git a/src/tests/test_unfold.f90 b/test/test_unfold.f90 similarity index 100% rename from src/tests/test_unfold.f90 rename to test/test_unfold.f90 diff --git a/src/tests/test_union.f90 b/test/test_union.f90 similarity index 100% rename from src/tests/test_union.f90 rename to test/test_union.f90 From e66a16dc00c4c488f4cec13add4611d8422ed4cb Mon Sep 17 00:00:00 2001 From: milancurcic Date: Thu, 19 Nov 2020 19:47:25 -0500 Subject: [PATCH 02/11] bump version --- VERSION | 2 +- fpm.toml | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/VERSION b/VERSION index 8f0916f..a918a2a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.0 +0.6.0 diff --git a/fpm.toml b/fpm.toml index 397e529..6099d78 100644 --- a/fpm.toml +++ b/fpm.toml @@ -1,9 +1,6 @@ name = "functional" -version = "0.5.0" +version = "0.6.0" license = "BSD-3-Clause" author = "Milan Curcic" -maintainer = "mcurcic@wavebitscientific.com" +maintainer = "milancurcic@hey.com" copyright = "Copyright (c) 2016-2020, functional-fortran contributors" - -[library] -source-dir = "src/lib" From 38e1814f75e809ba7cae8dee1659a5d4419d5406 Mon Sep 17 00:00:00 2001 From: milancurcic Date: Thu, 19 Nov 2020 19:47:48 -0500 Subject: [PATCH 03/11] ignore build/ directory --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 4581ef2..3830f1d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +build + # Compiled Object files *.slo *.lo From d3522d6efff08540755e2891e189d30002437031 Mon Sep 17 00:00:00 2001 From: milancurcic Date: Thu, 19 Nov 2020 19:48:14 -0500 Subject: [PATCH 04/11] remove AUTHORS file (obsolete) --- AUTHORS | 1 - 1 file changed, 1 deletion(-) delete mode 100644 AUTHORS diff --git a/AUTHORS b/AUTHORS deleted file mode 100644 index 8efdb02..0000000 --- a/AUTHORS +++ /dev/null @@ -1 +0,0 @@ -Milan Curcic From 842da928bf1031fa413604d9595acdfcf7669b92 Mon Sep 17 00:00:00 2001 From: milancurcic Date: Thu, 19 Nov 2020 19:56:55 -0500 Subject: [PATCH 05/11] move the function interfaces to the functional module; drop the mod_ prefix in module name --- src/{mod_functional.f90 => functional.f90} | 0 src/mod_interfaces.f90 | 281 --------------------- 2 files changed, 281 deletions(-) rename src/{mod_functional.f90 => functional.f90} (100%) delete mode 100644 src/mod_interfaces.f90 diff --git a/src/mod_functional.f90 b/src/functional.f90 similarity index 100% rename from src/mod_functional.f90 rename to src/functional.f90 diff --git a/src/mod_interfaces.f90 b/src/mod_interfaces.f90 deleted file mode 100644 index 86c84b6..0000000 --- a/src/mod_interfaces.f90 +++ /dev/null @@ -1,281 +0,0 @@ -module mod_interfaces -use iso_fortran_env, only:i1 => int8, i2 => int16, i4 => int32, i8 => int64, & - r4 => real32, r8 => real64, r16 => real128 -implicit none - -private - -public :: f_i1, f_i2, f_i4, f_i8 -public :: f_r4, f_r8, f_r16 -public :: f_c4, f_c8, f_c16 -public :: f_array_i1, f_array_i2, f_array_i4, f_array_i8 -public :: f_array_r4, f_array_r8, f_array_r16 -public :: f_array_c4, f_array_c8, f_array_c16 -public :: f2_i1, f2_i2, f2_i4, f2_i8 -public :: f2_r4, f2_r8, f2_r16 -public :: f2_c4, f2_c8, f2_c16 -public :: f_i1_logical, f_i2_logical, f_i4_logical, f_i8_logical -public :: f_r4_logical, f_r8_logical, f_r16_logical -public :: f_c4_logical, f_c8_logical, f_c16_logical -public :: f_char_logical - -interface - - pure integer(i1) function f_i1(x) - !! f :: i1 -> i1 - import :: i1 - integer(i1), intent(in) :: x - end function f_i1 - - pure integer(i2) function f_i2(x) - !! f :: i2 -> i2 - import :: i2 - integer(i2), intent(in) :: x - end function f_i2 - - pure integer(i4) function f_i4(x) - !! f :: i4 -> i4 - import :: i4 - integer(i4), intent(in) :: x - end function f_i4 - - pure integer(i8) function f_i8(x) - !! f :: i8 -> i8 - import :: i8 - integer(i8), intent(in) :: x - end function f_i8 - - pure real(r4) function f_r4(x) - !! f :: r4 -> r4 - import :: r4 - real(r4), intent(in) :: x - end function f_r4 - - pure real(r8) function f_r8(x) - !! f :: r8 -> r8 - import :: r8 - real(r8), intent(in) :: x - end function f_r8 - - pure real(r16) function f_r16(x) - !! f :: r16 -> r16 - import :: r16 - real(r16), intent(in) :: x - end function f_r16 - - pure complex(r4) function f_c4(x) - !! f :: c4 -> c4 - import :: r4 - complex(r4), intent(in) :: x - end function f_c4 - - pure complex(r8) function f_c8(x) - !! f :: c8 -> c8 - import :: r8 - complex(r8), intent(in) :: x - end function f_c8 - - pure complex(r16) function f_c16(x) - !! f :: c16 -> c16 - import :: r16 - complex(r16), intent(in) :: x - end function f_c16 - - pure function f_array_i1(x) result(f) - !! f :: [i1] -> [i1] - import :: i1 - integer(i1), dimension(:), intent(in) :: x - integer(i1), dimension(:), allocatable :: f - end function f_array_i1 - - pure function f_array_i2(x) result(f) - !! f :: [i2] -> [i2] - import :: i2 - integer(i2), dimension(:), intent(in) :: x - integer(i2), dimension(:), allocatable :: f - end function f_array_i2 - - pure function f_array_i4(x) result(f) - !! f :: [i4] -> [i4] - import :: i4 - integer(i4), dimension(:), intent(in) :: x - integer(i4), dimension(:), allocatable :: f - end function f_array_i4 - - pure function f_array_i8(x) result(f) - !! f :: [i8] -> [i8] - import :: i8 - integer(i8), dimension(:), intent(in) :: x - integer(i8), dimension(:), allocatable :: f - end function f_array_i8 - - pure function f_array_r4(x) result(f) - !! f :: [r4] -> [r4] - import :: r4 - real(r4), dimension(:), intent(in) :: x - real(r4), dimension(:), allocatable :: f - end function f_array_r4 - - pure function f_array_r8(x) result(f) - !! f :: [r8] -> [r8] - import :: r8 - real(r8), dimension(:), intent(in) :: x - real(r8), dimension(:), allocatable :: f - end function f_array_r8 - - pure function f_array_r16(x) result(f) - !! f :: [r16] -> [r16] - import :: r16 - real(r16), dimension(:), intent(in) :: x - real(r16), dimension(:), allocatable :: f - end function f_array_r16 - - pure function f_array_c4(x) result(f) - !! f :: [c4] -> [c4] - import :: r4 - complex(r4), dimension(:), intent(in) :: x - complex(r4), dimension(:), allocatable :: f - end function f_array_c4 - - pure function f_array_c8(x) result(f) - !! f :: [c8] -> [c8] - import :: r8 - complex(r8), dimension(:), intent(in) :: x - complex(r8), dimension(:), allocatable :: f - end function f_array_c8 - - pure function f_array_c16(x) result(f) - !! f :: [c16] -> [c16] - import :: r16 - complex(r16), dimension(:), intent(in) :: x - complex(r16), dimension(:), allocatable :: f - end function f_array_c16 - - pure integer(i1) function f2_i1(x, y) - !! f :: i1 i1 -> i1 - import :: i1 - integer(i1), intent(in) :: x, y - end function f2_i1 - - pure integer(i2) function f2_i2(x, y) - !! f :: i2 i2 -> i2 - import :: i2 - integer(i2), intent(in) :: x, y - end function f2_i2 - - pure integer(i4) function f2_i4(x, y) - !! f :: i4 i4 -> i4 - import :: i4 - integer(i4), intent(in) :: x, y - end function f2_i4 - - pure integer(i8) function f2_i8(x, y) - !! f :: i8 i8 -> i8 - import :: i8 - integer(i8), intent(in) :: x, y - end function f2_i8 - - pure real(r4) function f2_r4(x, y) - !! f :: r4 r4 -> r4 - import :: r4 - real(r4), intent(in) :: x, y - end function f2_r4 - - pure real(r8) function f2_r8(x, y) - !! f :: r8 r8 -> r8 - import :: r8 - real(r8), intent(in) :: x, y - end function f2_r8 - - pure real(r16) function f2_r16(x, y) - !! f :: r16 r16 -> r16 - import :: r16 - real(r16), intent(in) :: x, y - end function f2_r16 - - pure complex(r4) function f2_c4(x, y) - !! f :: c4 c4 -> c4 - import :: r4 - complex(r4), intent(in) :: x, y - end function f2_c4 - - pure complex(r8) function f2_c8(x, y) - !! f :: c8 c8 -> c8 - import :: r8 - complex(r8), intent(in) :: x, y - end function f2_c8 - - pure complex(r16) function f2_c16(x, y) - !! f :: c16 c16 -> c16 - import :: r16 - complex(r16), intent(in) :: x, y - end function f2_c16 - - pure logical function f_i1_logical(x) - !! f :: i1 -> logical - import :: i1 - integer(i1), intent(in) :: x - end function f_i1_logical - - pure logical function f_i2_logical(x) - !! f :: i2 -> logical - import :: i2 - integer(i2), intent(in) :: x - end function f_i2_logical - - pure logical function f_i4_logical(x) - !! f :: i4 -> logical - import :: i4 - integer(i4), intent(in) :: x - end function f_i4_logical - - pure logical function f_i8_logical(x) - !! f :: i8 -> logical - import :: i8 - integer(i8), intent(in) :: x - end function f_i8_logical - - pure logical function f_r4_logical(x) - !! f :: r4 -> logical - import :: r4 - real(r4), intent(in) :: x - end function f_r4_logical - - pure logical function f_r8_logical(x) - !! f :: r8 -> logical - import :: r8 - real(r8), intent(in) :: x - end function f_r8_logical - - pure logical function f_r16_logical(x) - !! f :: r16 -> logical - import :: r16 - real(r16), intent(in) :: x - end function f_r16_logical - - pure logical function f_c4_logical(x) - !! f :: c4 -> logical - import :: r4 - complex(r4), intent(in) :: x - end function f_c4_logical - - pure logical function f_c8_logical(x) - !! f :: c8 -> logical - import :: r8 - complex(r8), intent(in) :: x - end function f_c8_logical - - pure logical function f_c16_logical(x) - !! f :: c16 -> logical - import :: r16 - complex(r16), intent(in) :: x - end function f_c16_logical - - pure logical function f_char_logical(x) - !! f :: character -> logical - character(len=1), intent(in) :: x - end function f_char_logical - -end interface - -end module mod_interfaces From db9dfad9c7251c8c818acf2ba79c69d884b805c6 Mon Sep 17 00:00:00 2001 From: milancurcic Date: Thu, 19 Nov 2020 19:57:47 -0500 Subject: [PATCH 06/11] move the function interfaces to the functional module; drop the mod_ prefix in module name --- src/functional.f90 | 266 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 263 insertions(+), 3 deletions(-) diff --git a/src/functional.f90 b/src/functional.f90 index 7d6fc28..63d6b45 100644 --- a/src/functional.f90 +++ b/src/functional.f90 @@ -1,8 +1,7 @@ -module mod_functional +module functional use iso_fortran_env, only:i1 => int8, i2 => int16, i4 => int32, i8 => int64, & r4 => real32, r8 => real64, r16 => real128 -use mod_interfaces implicit none @@ -252,6 +251,267 @@ module mod_functional module procedure :: ge_c4, ge_c8, ge_c16 end interface operator(>=) + +interface + + pure integer(i1) function f_i1(x) + !! f :: i1 -> i1 + import :: i1 + integer(i1), intent(in) :: x + end function f_i1 + + pure integer(i2) function f_i2(x) + !! f :: i2 -> i2 + import :: i2 + integer(i2), intent(in) :: x + end function f_i2 + + pure integer(i4) function f_i4(x) + !! f :: i4 -> i4 + import :: i4 + integer(i4), intent(in) :: x + end function f_i4 + + pure integer(i8) function f_i8(x) + !! f :: i8 -> i8 + import :: i8 + integer(i8), intent(in) :: x + end function f_i8 + + pure real(r4) function f_r4(x) + !! f :: r4 -> r4 + import :: r4 + real(r4), intent(in) :: x + end function f_r4 + + pure real(r8) function f_r8(x) + !! f :: r8 -> r8 + import :: r8 + real(r8), intent(in) :: x + end function f_r8 + + pure real(r16) function f_r16(x) + !! f :: r16 -> r16 + import :: r16 + real(r16), intent(in) :: x + end function f_r16 + + pure complex(r4) function f_c4(x) + !! f :: c4 -> c4 + import :: r4 + complex(r4), intent(in) :: x + end function f_c4 + + pure complex(r8) function f_c8(x) + !! f :: c8 -> c8 + import :: r8 + complex(r8), intent(in) :: x + end function f_c8 + + pure complex(r16) function f_c16(x) + !! f :: c16 -> c16 + import :: r16 + complex(r16), intent(in) :: x + end function f_c16 + + pure function f_array_i1(x) result(f) + !! f :: [i1] -> [i1] + import :: i1 + integer(i1), dimension(:), intent(in) :: x + integer(i1), dimension(:), allocatable :: f + end function f_array_i1 + + pure function f_array_i2(x) result(f) + !! f :: [i2] -> [i2] + import :: i2 + integer(i2), dimension(:), intent(in) :: x + integer(i2), dimension(:), allocatable :: f + end function f_array_i2 + + pure function f_array_i4(x) result(f) + !! f :: [i4] -> [i4] + import :: i4 + integer(i4), dimension(:), intent(in) :: x + integer(i4), dimension(:), allocatable :: f + end function f_array_i4 + + pure function f_array_i8(x) result(f) + !! f :: [i8] -> [i8] + import :: i8 + integer(i8), dimension(:), intent(in) :: x + integer(i8), dimension(:), allocatable :: f + end function f_array_i8 + + pure function f_array_r4(x) result(f) + !! f :: [r4] -> [r4] + import :: r4 + real(r4), dimension(:), intent(in) :: x + real(r4), dimension(:), allocatable :: f + end function f_array_r4 + + pure function f_array_r8(x) result(f) + !! f :: [r8] -> [r8] + import :: r8 + real(r8), dimension(:), intent(in) :: x + real(r8), dimension(:), allocatable :: f + end function f_array_r8 + + pure function f_array_r16(x) result(f) + !! f :: [r16] -> [r16] + import :: r16 + real(r16), dimension(:), intent(in) :: x + real(r16), dimension(:), allocatable :: f + end function f_array_r16 + + pure function f_array_c4(x) result(f) + !! f :: [c4] -> [c4] + import :: r4 + complex(r4), dimension(:), intent(in) :: x + complex(r4), dimension(:), allocatable :: f + end function f_array_c4 + + pure function f_array_c8(x) result(f) + !! f :: [c8] -> [c8] + import :: r8 + complex(r8), dimension(:), intent(in) :: x + complex(r8), dimension(:), allocatable :: f + end function f_array_c8 + + pure function f_array_c16(x) result(f) + !! f :: [c16] -> [c16] + import :: r16 + complex(r16), dimension(:), intent(in) :: x + complex(r16), dimension(:), allocatable :: f + end function f_array_c16 + + pure integer(i1) function f2_i1(x, y) + !! f :: i1 i1 -> i1 + import :: i1 + integer(i1), intent(in) :: x, y + end function f2_i1 + + pure integer(i2) function f2_i2(x, y) + !! f :: i2 i2 -> i2 + import :: i2 + integer(i2), intent(in) :: x, y + end function f2_i2 + + pure integer(i4) function f2_i4(x, y) + !! f :: i4 i4 -> i4 + import :: i4 + integer(i4), intent(in) :: x, y + end function f2_i4 + + pure integer(i8) function f2_i8(x, y) + !! f :: i8 i8 -> i8 + import :: i8 + integer(i8), intent(in) :: x, y + end function f2_i8 + + pure real(r4) function f2_r4(x, y) + !! f :: r4 r4 -> r4 + import :: r4 + real(r4), intent(in) :: x, y + end function f2_r4 + + pure real(r8) function f2_r8(x, y) + !! f :: r8 r8 -> r8 + import :: r8 + real(r8), intent(in) :: x, y + end function f2_r8 + + pure real(r16) function f2_r16(x, y) + !! f :: r16 r16 -> r16 + import :: r16 + real(r16), intent(in) :: x, y + end function f2_r16 + + pure complex(r4) function f2_c4(x, y) + !! f :: c4 c4 -> c4 + import :: r4 + complex(r4), intent(in) :: x, y + end function f2_c4 + + pure complex(r8) function f2_c8(x, y) + !! f :: c8 c8 -> c8 + import :: r8 + complex(r8), intent(in) :: x, y + end function f2_c8 + + pure complex(r16) function f2_c16(x, y) + !! f :: c16 c16 -> c16 + import :: r16 + complex(r16), intent(in) :: x, y + end function f2_c16 + + pure logical function f_i1_logical(x) + !! f :: i1 -> logical + import :: i1 + integer(i1), intent(in) :: x + end function f_i1_logical + + pure logical function f_i2_logical(x) + !! f :: i2 -> logical + import :: i2 + integer(i2), intent(in) :: x + end function f_i2_logical + + pure logical function f_i4_logical(x) + !! f :: i4 -> logical + import :: i4 + integer(i4), intent(in) :: x + end function f_i4_logical + + pure logical function f_i8_logical(x) + !! f :: i8 -> logical + import :: i8 + integer(i8), intent(in) :: x + end function f_i8_logical + + pure logical function f_r4_logical(x) + !! f :: r4 -> logical + import :: r4 + real(r4), intent(in) :: x + end function f_r4_logical + + pure logical function f_r8_logical(x) + !! f :: r8 -> logical + import :: r8 + real(r8), intent(in) :: x + end function f_r8_logical + + pure logical function f_r16_logical(x) + !! f :: r16 -> logical + import :: r16 + real(r16), intent(in) :: x + end function f_r16_logical + + pure logical function f_c4_logical(x) + !! f :: c4 -> logical + import :: r4 + complex(r4), intent(in) :: x + end function f_c4_logical + + pure logical function f_c8_logical(x) + !! f :: c8 -> logical + import :: r8 + complex(r8), intent(in) :: x + end function f_c8_logical + + pure logical function f_c16_logical(x) + !! f :: c16 -> logical + import :: r16 + complex(r16), intent(in) :: x + end function f_c16_logical + + pure logical function f_char_logical(x) + !! f :: character -> logical + character(len=1), intent(in) :: x + end function f_char_logical + +end interface + + contains @@ -3930,4 +4190,4 @@ pure function union_char(x, y) result(union) union = set(x // y) end function union_char -end module mod_functional +end module functional From 90f37c10c1a3229ba7457e3bbe6797ee998f4c06 Mon Sep 17 00:00:00 2001 From: milancurcic Date: Thu, 19 Nov 2020 19:59:39 -0500 Subject: [PATCH 07/11] use functional instead of mod_functional --- test/test_arange.f90 | 2 +- test/test_arrstr.f90 | 2 +- test/test_complement.f90 | 2 +- test/test_empty.f90 | 2 +- test/test_filter.f90 | 2 +- test/test_foldl.f90 | 2 +- test/test_foldr.f90 | 2 +- test/test_foldt.f90 | 2 +- test/test_head.f90 | 2 +- test/test_init.f90 | 2 +- test/test_insert.f90 | 2 +- test/test_intersection.f90 | 2 +- test/test_iterfold.f90 | 2 +- test/test_last.f90 | 2 +- test/test_limit.f90 | 2 +- test/test_map.f90 | 2 +- test/test_reverse.f90 | 2 +- test/test_set.f90 | 2 +- test/test_sort.f90 | 2 +- test/test_split.f90 | 2 +- test/test_strarr.f90 | 2 +- test/test_subscript.f90 | 2 +- test/test_tail.f90 | 2 +- test/test_unfold.f90 | 2 +- test/test_union.f90 | 2 +- 25 files changed, 25 insertions(+), 25 deletions(-) diff --git a/test/test_arange.f90 b/test/test_arange.f90 index e2742bc..e86f255 100644 --- a/test/test_arange.f90 +++ b/test/test_arange.f90 @@ -1,7 +1,7 @@ program test_arange use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional, only:arange +use functional, only:arange implicit none diff --git a/test/test_arrstr.f90 b/test/test_arrstr.f90 index 1636af5..f15d195 100644 --- a/test/test_arrstr.f90 +++ b/test/test_arrstr.f90 @@ -1,6 +1,6 @@ program test_arrstr use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional, only:arrstr, empty +use functional, only:arrstr, empty implicit none diff --git a/test/test_complement.f90 b/test/test_complement.f90 index 6c0ccdf..4bc506c 100644 --- a/test/test_complement.f90 +++ b/test/test_complement.f90 @@ -1,7 +1,7 @@ program test_complement use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional implicit none diff --git a/test/test_empty.f90 b/test/test_empty.f90 index 25284b6..8d054c8 100644 --- a/test/test_empty.f90 +++ b/test/test_empty.f90 @@ -1,7 +1,7 @@ program test_empty use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional, only:empty +use functional, only:empty implicit none diff --git a/test/test_filter.f90 b/test/test_filter.f90 index 2bb5545..5517db7 100644 --- a/test/test_filter.f90 +++ b/test/test_filter.f90 @@ -71,7 +71,7 @@ end module mod_filter_functions program test_filter use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional use mod_filter_functions implicit none diff --git a/test/test_foldl.f90 b/test/test_foldl.f90 index e8f0852..49a909f 100644 --- a/test/test_foldl.f90 +++ b/test/test_foldl.f90 @@ -71,7 +71,7 @@ end module mod_fold_functions program test_foldl use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional use mod_fold_functions implicit none diff --git a/test/test_foldr.f90 b/test/test_foldr.f90 index 1cdc7c0..45cd2d8 100644 --- a/test/test_foldr.f90 +++ b/test/test_foldr.f90 @@ -71,7 +71,7 @@ end module mod_fold_functions program test_foldr use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional use mod_fold_functions implicit none diff --git a/test/test_foldt.f90 b/test/test_foldt.f90 index e88ea90..4c69791 100644 --- a/test/test_foldt.f90 +++ b/test/test_foldt.f90 @@ -71,7 +71,7 @@ end module mod_fold_functions program test_foldt use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional use mod_fold_functions implicit none diff --git a/test/test_head.f90 b/test/test_head.f90 index 43ba818..621c5d5 100644 --- a/test/test_head.f90 +++ b/test/test_head.f90 @@ -1,7 +1,7 @@ program test_head use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional implicit none diff --git a/test/test_init.f90 b/test/test_init.f90 index c76c783..b5f737d 100644 --- a/test/test_init.f90 +++ b/test/test_init.f90 @@ -1,7 +1,7 @@ program test_init use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional implicit none diff --git a/test/test_insert.f90 b/test/test_insert.f90 index 086d1f7..323d99e 100644 --- a/test/test_insert.f90 +++ b/test/test_insert.f90 @@ -1,7 +1,7 @@ program test_insert use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional implicit none diff --git a/test/test_intersection.f90 b/test/test_intersection.f90 index 4c126cf..2a45ed7 100644 --- a/test/test_intersection.f90 +++ b/test/test_intersection.f90 @@ -1,7 +1,7 @@ program test_intersection use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional implicit none diff --git a/test/test_iterfold.f90 b/test/test_iterfold.f90 index 545c0f4..0c3bba8 100644 --- a/test/test_iterfold.f90 +++ b/test/test_iterfold.f90 @@ -71,7 +71,7 @@ end module mod_iterfold_functions program test_iterfold use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional use mod_iterfold_functions implicit none diff --git a/test/test_last.f90 b/test/test_last.f90 index 2fa2387..6000ba8 100644 --- a/test/test_last.f90 +++ b/test/test_last.f90 @@ -1,7 +1,7 @@ program test_last use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional implicit none diff --git a/test/test_limit.f90 b/test/test_limit.f90 index 0e9593e..c78bb1f 100644 --- a/test/test_limit.f90 +++ b/test/test_limit.f90 @@ -1,7 +1,7 @@ program test_limit use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional, only:limit, arange +use functional, only:limit, arange implicit none diff --git a/test/test_map.f90 b/test/test_map.f90 index 13ef612..850a449 100644 --- a/test/test_map.f90 +++ b/test/test_map.f90 @@ -62,7 +62,7 @@ end module mod_map_functions program test_map use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional use mod_map_functions implicit none diff --git a/test/test_reverse.f90 b/test/test_reverse.f90 index 443c526..81b11d8 100644 --- a/test/test_reverse.f90 +++ b/test/test_reverse.f90 @@ -1,7 +1,7 @@ program test_reverse use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional implicit none diff --git a/test/test_set.f90 b/test/test_set.f90 index c19df23..9902460 100644 --- a/test/test_set.f90 +++ b/test/test_set.f90 @@ -1,7 +1,7 @@ program test_set use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional implicit none diff --git a/test/test_sort.f90 b/test/test_sort.f90 index 03b44f7..5afcf01 100644 --- a/test/test_sort.f90 +++ b/test/test_sort.f90 @@ -1,7 +1,7 @@ program test_sort use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional implicit none diff --git a/test/test_split.f90 b/test/test_split.f90 index d1cd5d6..2d7917b 100644 --- a/test/test_split.f90 +++ b/test/test_split.f90 @@ -1,7 +1,7 @@ program test_split use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional, only:arange, split +use functional, only:arange, split implicit none diff --git a/test/test_strarr.f90 b/test/test_strarr.f90 index 4901055..b88afb2 100644 --- a/test/test_strarr.f90 +++ b/test/test_strarr.f90 @@ -1,6 +1,6 @@ program test_strarr use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional, only:arrstr, strarr, empty +use functional, only:arrstr, strarr, empty implicit none diff --git a/test/test_subscript.f90 b/test/test_subscript.f90 index abefa47..2f4e16c 100644 --- a/test/test_subscript.f90 +++ b/test/test_subscript.f90 @@ -1,7 +1,7 @@ program test_subscript use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional implicit none diff --git a/test/test_tail.f90 b/test/test_tail.f90 index 54dc1fc..99008f4 100644 --- a/test/test_tail.f90 +++ b/test/test_tail.f90 @@ -1,7 +1,7 @@ program test_tail use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional implicit none diff --git a/test/test_unfold.f90 b/test/test_unfold.f90 index e976bc6..8e3572c 100644 --- a/test/test_unfold.f90 +++ b/test/test_unfold.f90 @@ -71,7 +71,7 @@ end module mod_unfold_functions program test_unfold use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional use mod_unfold_functions implicit none diff --git a/test/test_union.f90 b/test/test_union.f90 index 19da958..d4f1a5b 100644 --- a/test/test_union.f90 +++ b/test/test_union.f90 @@ -1,7 +1,7 @@ program test_union use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 use mod_testing, only:assert, initialize_tests, report_tests -use mod_functional +use functional implicit none From b50554b6583d37ff80336f5ed3221d832d9cb780 Mon Sep 17 00:00:00 2001 From: milancurcic Date: Thu, 19 Nov 2020 20:04:38 -0500 Subject: [PATCH 08/11] update CMakeLists for the new layout --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b0bc8c7..8a7dec9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,13 +34,13 @@ if(CMAKE_Fortran_COMPILER_ID MATCHES Cray) endif() # library to archive (libfunctional.a) -add_library(functional src/lib/mod_functional.f90 src/lib/mod_interfaces.f90) -add_library(testing src/tests/mod_testing.f90) +add_library(functional src/functional.f90) +add_library(testing test/mod_testing.f90) # tests enable_testing() foreach(execid arange arrstr complement empty filter foldl foldr foldt head init insert intersection iterfold last limit map reverse set sort split strarr subscript tail unfold union) - add_executable(test_${execid} src/tests/test_${execid}.f90) + add_executable(test_${execid} test/test_${execid}.f90) target_link_libraries(test_${execid} functional testing) add_test(test_${execid} bin/test_${execid}) endforeach() From 708919be33639ac8e5c5da7ffa3f7f40428166b2 Mon Sep 17 00:00:00 2001 From: milancurcic Date: Thu, 19 Nov 2020 20:21:41 -0500 Subject: [PATCH 09/11] update the README --- README.md | 191 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 111 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index 0668a42..3fe775f 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ Functional programming for modern Fortran. [![GitHub issues](https://img.shields.io/github/issues/wavebitscientific/functional-fortran.svg)](https://github.com/wavebitscientific/functional-fortran/issues) * [Getting started](#getting-started) + - [Get the code](#get-the-code) + - [Build with fpm](#build-with-fpm) + - [Build with CMake](#build-with-cmake) + - [Or just drop-in the source file](#or-just-drop-in-the-source-file) * [Why functional-fortran?](#why-functional-fortran) * [What's included?](#whats-included) * [Example usage](#example-usage) @@ -14,29 +18,56 @@ Functional programming for modern Fortran. ## Getting started +### Get the code + ``` git clone https://github.com/wavebitscientific/functional-fortran cd functional-fortran -mkdir build -cd build -cmake .. -make -ctest ``` -Start using functional-fortran in your code by including the module: + +### Build with fpm + +This project supports the Fortran Package Manager ([fpm](https://github.com/fortran-lang/fpm)). ``` -use mod_functional +fpm build --release +fpm test ``` -This project also supports the Fortran Package Manager ([fpm](https://github.com/fortran-lang/fpm)). +You can also use it as a dependency in your existing fpm package. Just add functional-fortran to your `fpm.toml`: + ```toml [dependencies] [dependencies.functional] git = "https://github.com/wavebitscientific/functional-fortran" ``` +### Build with CMake + +Alternatively, you can build functional-fortran with CMake: + +``` +mkdir build +cd build +cmake .. +make +ctest +``` + +### Or just drop-in the source file + +functional-fortran is a single-source library. +Just grab the src/functional.f90 file and build it however you want. + +### Use it + +Start using functional-fortran in your code by including the module: + +``` +use functional +``` + ## Why functional-fortran? While not designed as a purely functional programming language, @@ -51,29 +82,29 @@ be less imperative and more functional. The following functions are provided: -* `arange` - returns a regularly spaced array -* `complement` - returns a set complement of two arrays -* `empty` - returns an empty array -* `filter` - filters an array using a logical input function -* `foldl` - recursively left-folds an array using an input function -* `foldr` - recursively right-folds an array using an input function -* `foldt` - recursively tree-folds an array using an input function -* `head` - returns the first element of an array -* `init` - returns everything but the last element -* `insert` - inserts an element into an array, out-of-bound safe -* `intersection` - returns a set intersection of two arrays -* `iterfold` - iteratively reduces an array using an input function -* `last` - returns the last element of an array -* `limit` - limits a scalar or array by given lower and upper bounds -* `map` - maps an array with an input function -* `set` - returns a set given input array -* `reverse` - returns array in reverse order -* `sort` - recursive quicksort using binary tree pivot -* `split` - returns first or second half of an array -* `subscript` - out-of-bound safe implementation of vector subscript -* `tail` - returns everything but the first element -* `unfold` - unfolds an array with an input function -* `union` - returns a set union of two arrays +* `arange` returns a regularly spaced array +* `complement` returns a set complement of two arrays +* `empty` returns an empty array +* `filter` filters an array using a logical input function +* `foldl` recursively left-folds an array using an input function +* `foldr` recursively right-folds an array using an input function +* `foldt` recursively tree-folds an array using an input function +* `head` returns the first element of an array +* `init` returns everything but the last element +* `insert` inserts an element into an array, out-of-bound safe +* `intersection` returns a set intersection of two arrays +* `iterfold` iteratively reduces an array using an input function +* `last` returns the last element of an array +* `limit` limits a scalar or array by given lower and upper bounds +* `map` maps an array with an input function +* `set` returns a set given input array +* `reverse` returns array in reverse order +* `sort` is a recursive quicksort using binary tree pivot +* `split` returns first or second half of an array +* `subscript` is an out-of-bound safe implementation of vector subscript +* `tail` returns everything but the first element +* `unfold` unfolds an array with an input function +* `union` returns a set union of two arrays All of the above functions are compatible with the standard Fortran 2008 kinds: `int8`, `int16`, `int32`, `int64`, `real32`, `real64`, `real128`, @@ -97,14 +128,14 @@ unary or binary operators, respectively. These are: given start and end values as input arguments: ```fortran -write(*,*)arange(1,5) +write(*,*) arange(1, 5) 1 2 3 4 5 ``` `arange` works with real numbers as well: ```fortran -write(*,*)arange(1.,5.) +write(*,*) arange(1., 5.) 1.00000000 2.00000000 3.00000000 4.00000000 5.00000000 ``` @@ -112,21 +143,21 @@ Third argument to `arange` (optional) is the increment, which defaults to `1` if not given: ```fortran -write(*,*)arange(1,15,3) +write(*,*) arange(1, 15, 3) 1 4 7 10 13 ``` Negative increments work as expected: ```fortran -write(*,*)arange(3,1,-1) +write(*,*) arange(3, 1, -1) 3 2 1 ``` We can use floating-point increments: ```fortran -write(*,*)arange(1.,1.5,0.1) +write(*,*) arange(1., 1.5, 0.1) 1.00000000 1.10000002 1.20000005 1.29999995 1.39999998 1.50000000 ``` @@ -134,7 +165,7 @@ If `start` is greater than `end` and increment is positive, `arange` returns an empty array: ```fortran -write(*,*)arange(5,1) +write(*,*) arange(5, 1) ``` @@ -142,7 +173,7 @@ Use `empty` to generate a zero-length array of any Fortran standard kind: ```fortran -write(*,*)size(empty(1)) +write(*,*) size(empty(1)) 0 ``` which may be useful to initialize accumulators, for example @@ -152,43 +183,43 @@ see the implementation of set `intersection` in this library. `head` returns the first element of the array: ```fortran -write(*,*)head([1,2,3]) +write(*,*) head([1,2,3]) 1 ``` `tail` returns everything but the first element of the array: ```fortran -write(*,*)tail([1,2,3]) +write(*,*) tail([1,2,3]) 2 3 ``` Similarly, `last` returns the last element of the array: ```fortran -write(*,*)last([1,2,3]) +write(*,*) last([1,2,3]) 3 ``` `init` returns everything but the last element of the array: ```fortran -write(*,*)init([1,2,3]) +write(*,*) init([1,2,3]) 1 2 ``` Subscript an array at specific indices: ```fortran -write(*,*)subscript([1,2,3,4,5],[3,4]) +write(*,*) subscript([1,2,3,4,5], [3,4]) 3 4 ``` -Unlike Fortran 2008 vector subscript, the `subscript` function is out-of-bounds safe, +Unlike the Fortran 2008 vector subscript, the `subscript` function is out-of-bounds safe, i.e. subscripting out of bounds returns an empty array: ```fortran -write(*,*)subscript([1,2,3],[10]) +write(*,*) subscript([1,2,3], [10]) ``` @@ -196,15 +227,15 @@ We can prepend, append, or insert an element into an array using `insert`: ```fortran ! insert a 5 at position 0 to prepend: -write(*,*)insert(5,0,[1,2,3]) +write(*,*) insert(5, 0, [1,2,3]) 5 1 2 3 ! insert a 5 at position 4 to append: -write(*,*)insert(5,4,[1,2,3]) +write(*,*) insert(5, 4, [1,2,3]) 1 2 3 5 ! insert a 2 at position 2: -write(*,*)insert(2,2,[1,3,4]) +write(*,*) insert(2, 2, [1,3,4]) 1 2 3 4 ``` @@ -212,11 +243,11 @@ write(*,*)insert(2,2,[1,3,4]) ```fortran ! return first half of the array -write(*,*)split(arange(1,5),1) +write(*,*) split(arange(1, 5), 1) 1 2 ! return second half of the array -write(*,*)split(arange(1,5),2) +write(*,*) split(arange(1, 5), 2) 3 4 5 ``` The above is useful for recursive binary tree searching or sorting, @@ -225,9 +256,9 @@ for example, see the implementation of `sort` in this library. `sort` returns a sorted array in ascending order: ```fortran -real,dimension(5) :: x +real :: x(5) call random_number(x) -write(*,*)x +write(*,*) x 0.997559547 0.566824675 0.965915322 0.747927666 0.367390871 write(*,*)sort(x) 0.367390871 0.566824675 0.747927666 0.965915322 0.997559547 @@ -235,7 +266,7 @@ write(*,*)sort(x) Use `reverse` to sort in descending order: ```fortran -write(*,*)reverse(sort(x)) +write(*,*) reverse(sort(x)) 0.997559547 0.965915322 0.747927666 0.566824675 0.367390871 ``` @@ -244,17 +275,17 @@ or an array within a lower and upper limit, for example: ```fortran ! limit a scalar (5) within bounds 1 and 4 -write(*,*)limit(5,1,4) +write(*,*) limit(5, 1, 4) 4 ! flipping the bounds works just as well -write(*,*)limit(5,4,1) +write(*,*) limit(5, 4, 1) 4 ``` `limit` also works on arrays: ```fortran -write(*,*)limit(arange(0,4),1,3): +write(*,*) limit(arange(0, 4), 1, 3): 1 1 2 3 3 ``` @@ -266,16 +297,16 @@ but can be used to apply recursive functions to arrays, for example: ```fortran pure recursive integer function fibonacci(n) result(fib) integer,intent(in) :: n - if(n == 0)then + if (n == 0) then fib = 0 - elseif(n == 1)then + else if (n == 1) then fib = 1 else - fib = fibonacci(n-1)+fibonacci(n-2) - endif -endfunction fibonacci + fib = fibonacci(n - 1) + fibonacci(n - 2) + end if +end function fibonacci -write(*,*)map(fibonacci,[17,5,13,22]) +write(*,*) map(fibonacci, [17,5,13,22]) 1597 5 233 17711 ``` @@ -285,18 +316,18 @@ even number, and use this function to filter an array: ```fortran pure logical function even(x) - integer,intent(in) :: x + integer, intent(in) :: x even = .false. - if(mod(x,2) == 0)even = .true. + if(mod(x, 2) == 0) even = .true. endfunction even -write(*,*)filter(even,[1,2,3,4,5]) +write(*,*) filter(even,[1,2,3,4,5]) 2 4 ``` Functions can be chained together into pretty one-liners: ```fortran -write(*,*)filter(even,map(fibonacci,arange(1,10))) +write(*,*) filter(even,map(fibonacci,arange(1,10))) 2 8 34 ``` @@ -307,14 +338,14 @@ For simple examples of `sum` and `product` functions using folds, we can define the following addition and multiplication functions that operate on scalars: ```fortran -pure real function add(x,y) - real,intent(in) :: x,y - add = x+y +pure real function add(x, y) + real, intent(in) :: x, y + add = x + y endfunction add -pure real function mult(x,y) - real,intent(in) :: x,y - mult = x*y +pure real function mult(x, y) + real, intent(in) :: x, y + mult = x * y endfunction mult ``` We can then calculate the `sum` and `product` of an array by "folding" the @@ -323,11 +354,11 @@ input using the above-defined functions and a start value ```fortran ! left-fold an array using add to compute array sum -write(*,*)foldl(add,0.,arange(1.,5.)) +write(*,*) foldl(add,0.,arange(1.,5.)) 15.0000000 ! left-fold an array using mult to compute array product -write(*,*)foldl(mult,1.,arange(1.,5.)) +write(*,*) foldl(mult,1.,arange(1.,5.)) 120.000000 ``` The above is a trivial example that re-invents Fortran intrinsics @@ -347,10 +378,10 @@ For example: ```fortran pure real function multpt1(x) real,intent(in) :: x - multpt1 = 1.1*x + multpt1 = 1.1 * x endfunction multpt1 -write(*,*)unfold(multpt1,[1.],5) +write(*,*) unfold(multpt1,[1.],5) 1.00000000 1.10000002 1.21000004 1.33100009 1.46410012 ``` @@ -359,7 +390,7 @@ write(*,*)unfold(multpt1,[1.],5) Function `set` returns all unique elements of an input array: ```fortran -write(*,*)set([1,1,2,2,3]) +write(*,*) set([1,1,2,2,3]) 1 2 3 ``` Common functions that operate on sets, `union`, @@ -367,15 +398,15 @@ Common functions that operate on sets, `union`, ```fortran ! unique elements that are found in either array -write(*,*)union([1,2,2],[2,3,3,4]) +write(*,*) union([1,2,2],[2,3,3,4]) 1 2 3 4 ! unique elements that are found in both arrays -write(*,*)intersection([1,2,2],[2,3,3,4]) +write(*,*) intersection([1,2,2],[2,3,3,4]) 2 ! unique elements that are found first but not in second array -write(*,*)complement([1,2,2],[2,3,3,4]) +write(*,*) complement([1,2,2],[2,3,3,4]) 1 ``` From e2f486601eba822f846db01ca7ef7c9f4cd8b70a Mon Sep 17 00:00:00 2001 From: milancurcic Date: Thu, 19 Nov 2020 20:24:07 -0500 Subject: [PATCH 10/11] drop the mod_ prefix in the testing module --- test/test_arange.f90 | 2 +- test/test_arrstr.f90 | 2 +- test/test_complement.f90 | 2 +- test/test_empty.f90 | 2 +- test/test_filter.f90 | 2 +- test/test_foldl.f90 | 2 +- test/test_foldr.f90 | 2 +- test/test_foldt.f90 | 2 +- test/test_head.f90 | 2 +- test/test_init.f90 | 2 +- test/test_insert.f90 | 2 +- test/test_intersection.f90 | 2 +- test/test_iterfold.f90 | 2 +- test/test_last.f90 | 2 +- test/test_limit.f90 | 2 +- test/test_map.f90 | 2 +- test/test_reverse.f90 | 2 +- test/test_set.f90 | 2 +- test/test_sort.f90 | 2 +- test/test_split.f90 | 2 +- test/test_strarr.f90 | 2 +- test/test_subscript.f90 | 2 +- test/test_tail.f90 | 2 +- test/test_unfold.f90 | 2 +- test/test_union.f90 | 2 +- test/{mod_testing.f90 => testing.f90} | 4 ++-- 26 files changed, 27 insertions(+), 27 deletions(-) rename test/{mod_testing.f90 => testing.f90} (97%) diff --git a/test/test_arange.f90 b/test/test_arange.f90 index e86f255..3e3e71c 100644 --- a/test/test_arange.f90 +++ b/test/test_arange.f90 @@ -1,6 +1,6 @@ program test_arange use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional, only:arange implicit none diff --git a/test/test_arrstr.f90 b/test/test_arrstr.f90 index f15d195..195626f 100644 --- a/test/test_arrstr.f90 +++ b/test/test_arrstr.f90 @@ -1,5 +1,5 @@ program test_arrstr -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional, only:arrstr, empty implicit none diff --git a/test/test_complement.f90 b/test/test_complement.f90 index 4bc506c..304b4ba 100644 --- a/test/test_complement.f90 +++ b/test/test_complement.f90 @@ -1,6 +1,6 @@ program test_complement use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional implicit none diff --git a/test/test_empty.f90 b/test/test_empty.f90 index 8d054c8..7761d31 100644 --- a/test/test_empty.f90 +++ b/test/test_empty.f90 @@ -1,6 +1,6 @@ program test_empty use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional, only:empty implicit none diff --git a/test/test_filter.f90 b/test/test_filter.f90 index 5517db7..7f1df50 100644 --- a/test/test_filter.f90 +++ b/test/test_filter.f90 @@ -70,7 +70,7 @@ end module mod_filter_functions program test_filter use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional use mod_filter_functions diff --git a/test/test_foldl.f90 b/test/test_foldl.f90 index 49a909f..3f2788c 100644 --- a/test/test_foldl.f90 +++ b/test/test_foldl.f90 @@ -70,7 +70,7 @@ end module mod_fold_functions program test_foldl use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional use mod_fold_functions diff --git a/test/test_foldr.f90 b/test/test_foldr.f90 index 45cd2d8..2f74274 100644 --- a/test/test_foldr.f90 +++ b/test/test_foldr.f90 @@ -70,7 +70,7 @@ end module mod_fold_functions program test_foldr use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional use mod_fold_functions diff --git a/test/test_foldt.f90 b/test/test_foldt.f90 index 4c69791..033cc52 100644 --- a/test/test_foldt.f90 +++ b/test/test_foldt.f90 @@ -70,7 +70,7 @@ end module mod_fold_functions program test_foldt use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional use mod_fold_functions diff --git a/test/test_head.f90 b/test/test_head.f90 index 621c5d5..f575ea8 100644 --- a/test/test_head.f90 +++ b/test/test_head.f90 @@ -1,6 +1,6 @@ program test_head use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional implicit none diff --git a/test/test_init.f90 b/test/test_init.f90 index b5f737d..e962830 100644 --- a/test/test_init.f90 +++ b/test/test_init.f90 @@ -1,6 +1,6 @@ program test_init use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional implicit none diff --git a/test/test_insert.f90 b/test/test_insert.f90 index 323d99e..2d7cc00 100644 --- a/test/test_insert.f90 +++ b/test/test_insert.f90 @@ -1,6 +1,6 @@ program test_insert use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional implicit none diff --git a/test/test_intersection.f90 b/test/test_intersection.f90 index 2a45ed7..9c6782a 100644 --- a/test/test_intersection.f90 +++ b/test/test_intersection.f90 @@ -1,6 +1,6 @@ program test_intersection use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional implicit none diff --git a/test/test_iterfold.f90 b/test/test_iterfold.f90 index 0c3bba8..4003ca8 100644 --- a/test/test_iterfold.f90 +++ b/test/test_iterfold.f90 @@ -70,7 +70,7 @@ end module mod_iterfold_functions program test_iterfold use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional use mod_iterfold_functions diff --git a/test/test_last.f90 b/test/test_last.f90 index 6000ba8..a230fc1 100644 --- a/test/test_last.f90 +++ b/test/test_last.f90 @@ -1,6 +1,6 @@ program test_last use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional implicit none diff --git a/test/test_limit.f90 b/test/test_limit.f90 index c78bb1f..41ce681 100644 --- a/test/test_limit.f90 +++ b/test/test_limit.f90 @@ -1,6 +1,6 @@ program test_limit use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional, only:limit, arange implicit none diff --git a/test/test_map.f90 b/test/test_map.f90 index 850a449..388b6d6 100644 --- a/test/test_map.f90 +++ b/test/test_map.f90 @@ -61,7 +61,7 @@ end module mod_map_functions program test_map use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional use mod_map_functions diff --git a/test/test_reverse.f90 b/test/test_reverse.f90 index 81b11d8..b203289 100644 --- a/test/test_reverse.f90 +++ b/test/test_reverse.f90 @@ -1,6 +1,6 @@ program test_reverse use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional implicit none diff --git a/test/test_set.f90 b/test/test_set.f90 index 9902460..c45b5a2 100644 --- a/test/test_set.f90 +++ b/test/test_set.f90 @@ -1,6 +1,6 @@ program test_set use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional implicit none diff --git a/test/test_sort.f90 b/test/test_sort.f90 index 5afcf01..6693a80 100644 --- a/test/test_sort.f90 +++ b/test/test_sort.f90 @@ -1,6 +1,6 @@ program test_sort use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional implicit none diff --git a/test/test_split.f90 b/test/test_split.f90 index 2d7917b..b8a69cd 100644 --- a/test/test_split.f90 +++ b/test/test_split.f90 @@ -1,6 +1,6 @@ program test_split use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional, only:arange, split implicit none diff --git a/test/test_strarr.f90 b/test/test_strarr.f90 index b88afb2..fb9917b 100644 --- a/test/test_strarr.f90 +++ b/test/test_strarr.f90 @@ -1,5 +1,5 @@ program test_strarr -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional, only:arrstr, strarr, empty implicit none diff --git a/test/test_subscript.f90 b/test/test_subscript.f90 index 2f4e16c..f01d5c7 100644 --- a/test/test_subscript.f90 +++ b/test/test_subscript.f90 @@ -1,6 +1,6 @@ program test_subscript use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional implicit none diff --git a/test/test_tail.f90 b/test/test_tail.f90 index 99008f4..f608f13 100644 --- a/test/test_tail.f90 +++ b/test/test_tail.f90 @@ -1,6 +1,6 @@ program test_tail use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional implicit none diff --git a/test/test_unfold.f90 b/test/test_unfold.f90 index 8e3572c..549db06 100644 --- a/test/test_unfold.f90 +++ b/test/test_unfold.f90 @@ -70,7 +70,7 @@ end module mod_unfold_functions program test_unfold use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional use mod_unfold_functions diff --git a/test/test_union.f90 b/test/test_union.f90 index d4f1a5b..c54e271 100644 --- a/test/test_union.f90 +++ b/test/test_union.f90 @@ -1,6 +1,6 @@ program test_union use iso_fortran_env, only:int8, int16, int32, int64, real32, real64, real128 -use mod_testing, only:assert, initialize_tests, report_tests +use testing, only:assert, initialize_tests, report_tests use functional implicit none diff --git a/test/mod_testing.f90 b/test/testing.f90 similarity index 97% rename from test/mod_testing.f90 rename to test/testing.f90 index efed2e1..0a68f79 100644 --- a/test/mod_testing.f90 +++ b/test/testing.f90 @@ -1,4 +1,4 @@ -module mod_testing +module testing ! Simple unit testing module. @@ -60,4 +60,4 @@ subroutine report_tests(tests, test_failed) end if end subroutine report_tests -end module mod_testing +end module testing From ed80bfcf0069a1fad05ce5ae0b4e4371ddb2ec01 Mon Sep 17 00:00:00 2001 From: milancurcic Date: Thu, 19 Nov 2020 22:05:55 -0500 Subject: [PATCH 11/11] fix CMakeLists --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a7dec9..e013370 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,7 @@ endif() # library to archive (libfunctional.a) add_library(functional src/functional.f90) -add_library(testing test/mod_testing.f90) +add_library(testing test/testing.f90) # tests enable_testing()