Re: Blog: Is Fortran better than Python for teaching the basics of numerical linear algebra?

"Steven G. Kargl" <[email protected]>
Newsgroups sci.math,comp.lang.fortran,comp.lang.python
Organization A noiseless patient Spider
Message-ID <[email protected]>
On Sun, 6 Sep 2026 22:00:39 -0000 (UTC), Lawrence D’Oliveiro wrote:

> On Sun, 6 Sep 2026 15:32:53 -0000 (UTC), Thomas Koenig wrote:
> 
>> Fortran 77 makes little sense, modern Fortran variants (Fortran 90+)
>> are available with free compilers and offer much more comfort and
>> safety.
> 
> Python offers custom operator overloads, so you can write actual
> operator expressions for addition, dot product etc -- closer in
> appearance to the actual maths -- instead of parenthesis-ridden
> function calls.

Can we assume you know little to nothing about modern
Fortran?  One can write custom operator overloads in
Fortran.  Here's a Cartesian point with a translation
and scaling operators.

module pointm

   implicit none

   type point_t
      real x, y, z
   end type point_t

   interface operator(-)
      module procedure translate
   end interface

   interface operator(*)
      module procedure left
      module procedure rght
   end interface

   contains

      function translate(pt1, pt2) result(r)
         type(point_t) r
         type(point_t), intent(in) :: pt1, pt2
         r%x = pt1%x - pt2%x
         r%y = pt1%y - pt2%y
         r%z = pt1%z - pt2%z
      end function translate

      function left(c, pt1) result(r)
         type(point_t) r
         real, intent(in) :: c
         type(point_t), intent(in) :: pt1
         r%x = c * pt1%x
         r%y = c * pt1%y
         r%z = c * pt1%z
      end function left

      function rght(pt1, c) result(r)
         type(point_t) r
         real, intent(in) :: c
         type(point_t), intent(in) :: pt1
         r%x = c * pt1%x
         r%y = c * pt1%y
         r%z = c * pt1%z
      end function rght

end module pointm

program foo
   use pointm
   type(point_t) :: a = point_t(1, 1, 1),  b = point_t(0.5, 0.75, 2)
   print "(3F6.2)", a - b
   print "(3F6.2)", 3. * a - 4. * b
end program

-- 
steve
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.