Aliasing intrinsic procedures

Suppose that I would like to invoke the intrinsic function matmul using the name matrix_product, what should I do?

Thanks.

1 Like

create a module composed of INTRINSIC statements.
Use the module and rename the intrinsic names on the USE statement.

click for example
module M_rename
implicit none
public
intrinsic :: abs,                   achar,                     acos,              acosh,             adjustl
intrinsic :: adjustr,               aimag,                     aint,              all,               allocated
intrinsic :: anint,                 any,                       asin,              asinh,             associated
intrinsic :: atan,                  atan2,                     atanh,             atomic_add,        atomic_and
intrinsic :: atomic_cas,            atomic_define,             atomic_fetch_add,  atomic_fetch_and,  atomic_fetch_or
intrinsic :: atomic_fetch_xor,      atomic_or,                 atomic_ref,        atomic_xor,        bessel_j0
intrinsic :: bessel_j1,             bessel_jn,                 bessel_y0,         bessel_y1,         bessel_yn
intrinsic :: bge,                   bgt,                       bit_size,          ble,               blt
intrinsic :: btest,                 ceiling,                   char,              cmplx,             command_argument_count
intrinsic :: conjg,                 cos,                       cosh,              count,             cpu_time
intrinsic :: cshift,                date_and_time,             dble,              digits,            dim
intrinsic :: dot_product,           dprod,                     dshiftl,           dshiftr,           eoshift
intrinsic :: epsilon,               erf,                       erfc,              erfc_scaled,       event_query
intrinsic :: execute_command_line,  exp,                       exponent,          extends_type_of,   findloc
intrinsic :: float,                 floor,                     fraction,          gamma,             get_command
intrinsic :: get_command_argument,  get_environment_variable,  huge,              hypot,             iachar
intrinsic :: iall,                  iand,                      iany,              ibclr,             ibits
intrinsic :: ibset,                 ichar,                     ieor,              image_index,       index
intrinsic :: int,                   ior,                       iparity,           is_contiguous,     ishft
intrinsic :: ishftc,                is_iostat_end,             is_iostat_eor,     kind,              lbound
intrinsic :: leadz,                 len,                       len_trim,          lge,               lgt
intrinsic :: lle,                   llt,                       log,               log10,             log_gamma
intrinsic :: logical,               maskl,                     maskr,             matmul,            max
intrinsic :: maxexponent,           maxloc,                    maxval,            merge,             merge_bits
intrinsic :: min,                   minexponent,               minloc,            minval,            mod
intrinsic :: modulo,                move_alloc,                mvbits,            nearest,           new_line
intrinsic :: nint,                  norm2,                     not,               null,              num_images
intrinsic :: pack,                  parity,                    popcnt,            poppar,            precision
intrinsic :: present,               product,                   radix,             random_number,     random_seed
intrinsic :: range,                 rank,                      real,              repeat,            reshape
intrinsic :: rrspacing,             same_type_as,              scale,             scan,              selected_char_kind
intrinsic :: selected_int_kind,     selected_real_kind,        set_exponent,      shape,             shifta
intrinsic :: shiftl,                shiftr,                    sign,              sin,               sinh
intrinsic :: size,                  sngl,                      spacing,           spread,            sqrt
intrinsic :: storage_size,          sum,                       system_clock,      tan,               tanh
intrinsic :: this_image,            tiny,                      trailz,            transfer,          transpose
intrinsic :: trim,                  ubound,                    unpack,            verify
end module M_rename
program tryit
use M_rename, only : cosine=>cos, sine=>sin, tangent=>tan
   write(*,*)cosine(1.0),sine(1.0),tangent(1.0)
end program tryit
2 Likes

preprocessing is probably more efficient. Using the module does not have a problem with the macro expanding longer than currently allowed line lengths; and if used without the ONLY qualifier prevents you from using function names as variable names (at least the currently named ones) which bothers people who do not like Fortran not having reserved names (which I personally like a lot), and lets you easily overload intrinsics (I like to make FLOAT() and INT() take string input myself, for one example) and easily switch to debug versions (an INT() that checks for out-of-range inputs, for example) of intrinsics; so it does have a few features that can be useful.

Not really sure how bad it might affect optimization but would not be surprised if it does; so unless you are looking for some of the other behaviors a preprocessor macro really does seem simpler.

If the preprocessor gets standardized it would be even better.

1 Like