(j3.2006) Why is the Passed-Object Argument Explicit?

Damian Rouson sourcery
Tue Feb 4 17:36:39 EST 2014


>> 
>> On Feb 4, 2014, at 1:49 PM, Craig Dedo <craig at ctdedo.com> wrote:
>> 
>>> Everyone:
>>>            Yesterday, on the Intel Visual Fortran (IVF) Developers Forum, Jim Dempsey asked this question:
>>> [Quote]
>>> Do you know why the Fortran standards committee did not choose to make the ?this? arg implicit?  (like most other OO languages)
>>> [End of quote]


I don?t know the history of the decision, but I can share two reasons that I like it:

1. I can name the argument whatever I like.
2. I can specify argument attributes such as ?intent(in)? or ?pointer?.

Here?s an example that takes advantage of these two features:

module vector_field_module
  implicit none
  type foo
    real :: component=0.
  contains
    procedure :: add
    generic :: operator(+)=>add
  end type
contains
  function add(lhs,rhs) result(total)
    class(foo), intent(in) :: lhs,rhs
    type(foo) :: total
    total%component = lhs%component + rhs%component
  end function
end module

Damian






More information about the J3 mailing list