Fortran calls can name arguments explicitly. Keyword calls make the mapping clear and can appear in a different order.

Program

Play the program to call the same function with two keyword argument orders.

subtotal
keyword_arguments.f90
Replay: real traced execution (multi-file project)
program keyword_arguments_demo
    implicit none
    integer :: subtotal, tax, total

    subtotal = 20
    tax = add_tax(amount=subtotal, rate=2)
    total = add_tax(rate=3, amount=subtotal)
    print '(I0, A, I0)', tax, " ", total
contains
    function add_tax(amount, rate) result(out)
        integer, intent(in) :: amount, rate
        integer :: out
        out = amount + rate
    end function add_tax
end program keyword_arguments_demo
program keyword_arguments_demo
    implicit none
    integer :: subtotal, tax, total

    subtotal = 15
    tax = add_tax(amount=subtotal, rate=2)
    total = add_tax(rate=3, amount=subtotal)
    print '(I0, A, I0)', tax, " ", total
contains
    function add_tax(amount, rate) result(out)
        integer, intent(in) :: amount, rate
        integer :: out
        out = amount + rate
    end function add_tax
end program keyword_arguments_demo
program keyword_arguments_demo
    implicit none
    integer :: subtotal, tax, total

    subtotal = 30
    tax = add_tax(amount=subtotal, rate=2)
    total = add_tax(rate=3, amount=subtotal)
    print '(I0, A, I0)', tax, " ", total
contains
    function add_tax(amount, rate) result(out)
        integer, intent(in) :: amount, rate
        integer :: out
        out = amount + rate
    end function add_tax
end program keyword_arguments_demo
  1. subtotal ← 20

    5subtotal = 206tax = add_tax(amount=subtotal, rate=2)
    values this step20subtotal
  2. tax ← 22

    5subtotal = 206tax = add_tax(amount=subtotal, rate=2)7total = add_tax(rate=3, amount=subtotal)
    values this step22tax20subtotal2rate
  3. total ← 23

    6tax = add_tax(amount=subtotal, rate=2)7total = add_tax(rate=3, amount=subtotal)8print '(I0, A, I0)', tax, " ", total
    values this step23total20subtotal3rate
  4. print '(I0, A, I0)', tax, " ", total

    7    total = add_tax(rate=3, amount=subtotal)8    print '(I0, A, I0)', tax, " ", total9contains
    output22 23
    values this step22tax23total
  1. subtotal ← 15

    5subtotal = 156tax = add_tax(amount=subtotal, rate=2)
    values this step15subtotal
  2. tax ← 17

    5subtotal = 156tax = add_tax(amount=subtotal, rate=2)7total = add_tax(rate=3, amount=subtotal)
    values this step17tax15subtotal2rate
  3. total ← 18

    6tax = add_tax(amount=subtotal, rate=2)7total = add_tax(rate=3, amount=subtotal)8print '(I0, A, I0)', tax, " ", total
    values this step18total15subtotal3rate
  4. print '(I0, A, I0)', tax, " ", total

    7    total = add_tax(rate=3, amount=subtotal)8    print '(I0, A, I0)', tax, " ", total9contains
    output17 18
    values this step17tax18total
  1. subtotal ← 30

    5subtotal = 306tax = add_tax(amount=subtotal, rate=2)
    values this step30subtotal
  2. tax ← 32

    5subtotal = 306tax = add_tax(amount=subtotal, rate=2)7total = add_tax(rate=3, amount=subtotal)
    values this step32tax30subtotal2rate
  3. total ← 33

    6tax = add_tax(amount=subtotal, rate=2)7total = add_tax(rate=3, amount=subtotal)8print '(I0, A, I0)', tax, " ", total
    values this step33total30subtotal3rate
  4. print '(I0, A, I0)', tax, " ", total

    7    total = add_tax(rate=3, amount=subtotal)8    print '(I0, A, I0)', tax, " ", total9contains
    output32 33
    values this step32tax33total
keyword argument `amount=subtotal` binds by dummy-argument name.
order independence Keyword arguments can be written in a different order.
explicit interface Contained procedures have an explicit interface, enabling keyword calls.