F (programming language)

Not to be confused with F Sharp (programming language).
F language
Paradigm module-oriented programming

F is a module-oriented, compiled and numeric computer programming language. F is designed for scientific programming and scientific computation.[1] F was developed by the Fortran Company and was developed as a modern Fortran thus making it a subset of Fortran 95 and Fortran 90[2] programming language. It combines both numerical features and data abstraction features from these languages.F is also backwards compatibility thus allowing to make calls to Fortran 77 program. F uses the g95 compiler, which is the same compiler used for Fortran 95. F compilers are readily available on both Windows and various Linux Operating Systems free of charge or can be as part of a bundle from the Fortran Store.

Overview

F is not permissive thus there is only one way to write codes.[2] All key words and function names are reserved words in F therefore names cannot be the same as any keyword. F is equipped with more than one hundred intrinsic procedures built into it therefore does not need to include additional standard libraries or modules.[3] Language keywords and intrinsic function names are reserved keywords in F and no other names may take this exact form.

F contains the same set of character used in Fortran 90/95 with a limit of 132 characters. Reserved words are always written in lowercase. Any uppercase letter may appear in a character constant. Variable names do not have restrictions therefore can include upper and lowercase characters. Quotes are used as delimiter for a character string.

F supports formatting. A format consist of a * (for list-directed formatting) or a list of edit descriptors, control edit descriptors or format list items. The comma is used to separate format items. Characters are not allowed after the final right parenthesis in a format specifier or character format variable.[2] The control descriptors are tn, tln, trn, [r]/, :, s, sp, ss.. F does not support carriage control; it is file and OS dependent.

Operators

F supports many of the standard operators used in many other languages. The operators supported by F are:

The assignment operator is denoted by the equal sign "=". In addition, pointer assignment is denoted by "=>". Comments are denoted by the "!" symbol.

variable = expression ! assignment 
pointer => target ! pointer assignment

Statement and Control Flow

F supports 3 types of control construct: the if construct, case construct, and the do construct.

There are also two other statements that may alter the order of execution of F statements. The return and stop statement.


Example of control constructs:

real:: x
do i = 100
   x += i
   print i
   cycle
end do
 
max : do
   if ( x > y) then
      exit max:
    end if
  x = y;
end max
stop
 
if (x < y) then
      x = x + y;
else if ( x > y) then
     x = y - x;
end if
 
select case (maximum):
     case (0)
         x = 0
     case (1)
         x = 1
     case (5)
         x = 5
     case default 
         x = 10
end select

Modules Program units in the F language are programs.[2] A main program begins with a program statement and ends at an end program statement.

program main
    ...
end program main

F does not accept procedures that are not in a module. F supports most of the modules and module procedures of Fortran 90/95. Functions and subroutines are part of the module procedures. All procedure dummy argument must be described with an interface block. F does not support internal procedures. All procedures requires a result clause that returns the value of a function.[2] Functions are not allowed to change the value of the dummy argument. F supports recursion.
Module procedures can be referenced by 'call statements. Whenever an intrinsic procedure is used as an argument or extended with a module procedure, the name must also be declared in an intrinsic statement. Intrinsic procedures are procedures provided by F. Most of Fortran 90/95 intrinsic procedures are included in F. These procedures are reserved words. There are some procedures that were in Fortran 90/95 but omitted in F: achar, iachar, lge, lgt, lge, llt, transfer, dble, dim, dprod, and mod.
An interface block makes a non-F procedure declaration explicit. User-defined operators and user-defined assignment must appear in an interface block.

interface operator ( defined operator )
     ...
    module procedure name
    ....
end interface [operator ( defined operator )]
interface assignment (=)
   ...
   module procedure name
   ...
end interface [ assignment (=)]

I/O (Input and Output)

F supports standard keyboard input and standard display and text output. Every input and output statements must be followed by a control list. The i/o control list must contain a unit number. They can also contain optional items such as fmt, advance, isotat, rec, and size. If the unit is a character then the i/o is for an internal file. The * is used for list-directory formatting or default formatting. This is used with the read and print statement. F also supports traditional unformatted input/output. The input statement syntax:

read (i/o control list ) [input list]
read format [, variable list]

Output statement syntax:

write (i/o control list ) [output list]
print format [, output list]

Data Types

Similar to Fortran, the type specification is made up of a type,a list of attributes for the declared variables, and the variable list.[2] The intrinsic types are:integer, real, complex, character, logical

Variable declarations are followed by an attribute list. The attributes allowed are parameter, public, private, allocatable, dimension (dimension of array), intent, optional, pointer, save and target. The attribute list is followed by "::"" (double colons), which are part of the syntax. F also allows for optional initialization in the list of objects.
Example of the informal syntax of type declaration:

! type [,attribute list] :: entity declaration list
real :: x, y ! declaring variables of type real x,y without an attribute list
integer (kind = long), dimension (100) :: x ! declaring variable of type big integer array with the identifier x
 character (len = 100) :: student_name ! declaring a character type variable with len 100

Although F does is a module-oriented language and does not support classes, programmers may create their own user-defined type. User defined types are similar to Structs in C and C++, where the type is used to cohesively placed differently types of variables in a single structure.[2]

For example:

type, public :: City
     character (len = 100) :: name
     character (len = 50):: state
end type City

All items in a list will have the same attributes in a given type declaration statement. In addition, declarations are attribute oriented instead of entity oriented.

References

  1. The Fortran Company. "All About F". Retrieved 2014-04-28.
  2. 2.0 2.1 2.2 2.3 2.4 2.5 2.6 Jeanne Adams. "The F Language". Retrieved 2014-04-28.
  3. Walt Brainerd, David Epstein, Richard Hendrickson. "The F Programming Language Tastes Like Java". Retrieved 2014-04-29.

External links