Fortran and Python (was Re: Statement function host association)



James Giles wrote:

> The problem with that is I would prefer that statement functions
> be inherently generic. That is, the return type of the statement
> function should be the result type (rank, KIND) of the expression
> that defines it based on the types (ranks, KINDs) of the actual
> arguments to the function.

Are trying to sneak Python into Fortran? :) Python does not have
declarations, and I think functions in Python have the property you
described.

Some features in Python (and in some other languages) that are
introduced in Fortran 2003 (in a different form) are

(1) classes with inheritance
(2) procedures taking allocatable arrays as arguments and returned
values (F95 already allows pointer arguments)
(3) automatic allocation of arrays in an expression

(my understanding is that if x has known dimensions, and y has not been
allocated yet, and x and y have the same rank, then the statement

y = x

both allocates y and sets its elements equal to those of x)

(5) allocatable structure components
(6) interoperability with C

I think features (2) and (3), along with the array operations and
intrinsic function present since Fortran 90, are giving Fortran some of
the features of a high-level scientific scripting language (similar to
Python with Numarray, or Matlab/Octave/Scilab, or IDL, or R/S-Plus),
which is a good thing IMO, as long as users still get good performance
and stand-alone executables. Getting non-Fortran-95 programmers to
think of the language this way is difficult.

.



Relevant Pages

  • Re: INTERFACE problem
    ... I have an integer at Fortran side, pass it by reference to C function, treat here as pointer, allocate memory and this C-pointer at Fortran side now is an integer which has represents address allocated at C side. ... I did something like this many years ago to allow dynamic allocation ... Then it was converted into a subroutine with the arrays and ... it called the sub by way of Pascal with those "pointers". ...
    (comp.lang.fortran)
  • Re: Speed penalty for using allocatable arrays?
    ... "Leading dimension" means dimension 1, ... Fortran compilers, rather than having being left those writing Fortran ... allocation available in Fortran 90/95. ... the arrays are allocated once at the ...
    (comp.lang.fortran)
  • Re: Fortran memory allocation (stack/heap) issues
    ... > rather than Fortran, ... dynamic allocation, and relatively little stack allocation. ... value return and arrays by reference. ...
    (comp.lang.fortran)
  • Re: dgemm subroutine in BLAS - I think Ive cracked the difference, please confirm
    ... > matrix and m,n,k define the dimensions of the actual matrix to be worked ... Now that you know all about Fortran arrays and memory use, ... While newer Fortran versions actually supply dymamic allocation ...
    (comp.lang.fortran)
  • Re: Why Python does *SLICING* the way it does??
    ... Some algorithms are specified in terms of 1-based arrays. ... Fortran programs are written in terms of 1-based arrays. ... want to implement a 1-based specification in Python, ... The book "Numerical Recipes in C" contains a lot of numerical ...
    (comp.lang.python)