For Programmers: Free Programming Magazines  


Home > Archive > Fortran > December 2006 > F2003: creating polymorphic entities









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author F2003: creating polymorphic entities
Reinhold Bader

2006-12-19, 8:09 am

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

C509 of the Fortran 2003 standard says:

An entity declared with the CLASS keyword shall be a dummy argument
or have the ALLOCATABLE or POINTER attribute.

Am I right in surmising that this implies that it is not possible to have
an allocatable or pointer dummy which is polymorphic?

If yes, this is rather a problem for programming of factory methods -
I'd rather like be able to do something like

module ....
: ! define extensible types x, x_1, ...
contains
subroutine create(this, fname)
class(x), allocatable, intent(out) :: this ! probably illegal
character(len=:) :: fname
:
open(unit, file=fname, ...)
read(unit) mytype
select case(mytype)
:
case(5)
allocate(x_5 :: this) ! x_5 an extension of x

:
end select
! use select type to insert further information from file into this
end subroutine
end module

As things appear to me now, a global polymorphic must be used, which is not
supposed to be good programming practice. Or are there good alternatives
available which I haven't hit upon yet?

Regards
Reinhold
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFh/ DCFVLhKuD7VgsRAt4tAJ9ZHoSJxzGHQF+SuavgIL
QtH6q9tQCfRnPQ
QLLvlzvNFHlP6cVDDciha9Q=
=xbyO
-----END PGP SIGNATURE-----
Brooks Moses

2006-12-19, 7:10 pm

Reinhold Bader wrote:
> C509 of the Fortran 2003 standard says:
>
> An entity declared with the CLASS keyword shall be a dummy argument
> or have the ALLOCATABLE or POINTER attribute.
>
> Am I right in surmising that this implies that it is not possible to have
> an allocatable or pointer dummy which is polymorphic?


I can't see any reason why that would be correct -- the Fortran standard
does not use "or" to mean "exclusive or" in such phrases, and so it is
perfectly allowable for an entity declared with the CLASS keyword to be
both ALLOCATABLE and a dummy.

- Brooks


--
The "bmoses-nospam" address is valid; no unmunging needed.
Richard E Maine

2006-12-19, 7:10 pm

Brooks Moses <bmoses-nospam@cits1.stanford.edu> wrote:

> Reinhold Bader wrote:
>
> I can't see any reason why that would be correct -- the Fortran standard
> does not use "or" to mean "exclusive or" in such phrases, and so it is
> perfectly allowable for an entity declared with the CLASS keyword to be
> both ALLOCATABLE and a dummy.


I agree with Brooks. In fact, until he pointed it out, I couldn't even
guess how anyone would read the cited sentence to prohibit that. I had
forgotten about the way that some people read the English "or" as being
exclusive. As Brooks says, the standard most definitely does not use it
that way.

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
Reinhold Bader

2006-12-19, 7:10 pm

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Brooks, Richard,

thanks for pointing this out.

At some point I became with a different prohibition concerning
the passed object dummy (which indeed may not be allocatable or
pointer), but if you implement the factory method not as a TBP but
simply as a contained subroutine things are fine.

Regards

Richard E Maine wrote:
> Brooks Moses <bmoses-nospam@cits1.stanford.edu> wrote:
>
>
> I agree with Brooks. In fact, until he pointed it out, I couldn't even
> guess how anyone would read the cited sentence to prohibit that. I had
> forgotten about the way that some people read the English "or" as being
> exclusive. As Brooks says, the standard most definitely does not use it
> that way.
>


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFFiFitzwkB8vcRvCoRAiM9AJ43jvpvQitv
6p8/dzYxkCLe+drXEwCeOCm3
BQSx1Ql10T51acZ+Ea/K2hE=
=nwq2
-----END PGP SIGNATURE-----
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com