(j3.2006) ERROR STOP stop-code in PURE procedures
Bill Long
longb
Thu Mar 19 09:13:48 EDT 2015
On Mar 18, 2015, at 5:39 PM, Damian Rouson <damian at sourceryinstitute.org> wrote:
> All,
>
> At the most recent J3 meeting, there was a discussion of whether to allow the ERROR STOP stop-code to be anything other than scalar-default-char-constant-expr or scalar-int-constant-expr. I believe Bill commented that this would be syntactic sugar (not necessarily using that terminology) that a user could always emulate simply by writing to ERROR_UNIT just before the execution of the ERROR STOP. There is one case, however, where the latter approach fails: the draft Fortran 2015 standard allows ERROR STOP inside PURE procedures, but input/output in PURE procedures is disallowed.
>
This seems like a valid use case. The idea that I/O is disallowed in a PURE procedure is a but mirky already when you allow a stop code of any kind to be output. However, ERROR STOP is a special case because the whole program is taking a dive anyway, so any benefit from purity would seem irrelevant at that point.
Cheers,
Bill
> This severely limits the use of general error-handling code inside PURE procedures. For example, it can be useful to write a general collection of assertion procedures, one very simple example of which follows:
>
> pure subroutine assert(assertion,error_text)
> logical, intent(in) :: assertion
> character(len=*), intent(in) :: error_text
> if (.not. assertion) error stop "scalar_assert: assertion fails with the message" // error_text
> end subroutine
>
> I think it aids code clarity to be able to call such assertions at the beginning and end of every procedure in a style inspired by programming by contract. Without the ability to have a non-constant stop-code, however, such procedures are much less useful because they either (1) can?t be PURE and therefore can't be called inside PURE procedures or (2) must print the same stop-code no matter what procedure calls the assertion procedure.
>
> I hope the addition of non-constant stop-codes can be considered as wart removal. It addresses the interaction between two existing features PURE and ERROR STOP in a way that only becomes possible in the draft standard. If others agree, I volunteer to work on the proposed edits.
>
> Damian
>
> P.S. In anticipation of the draft standard, the pre-release GFortran 5.0 compiler added support for ERROR STOP inside PURE procedures about three months ago.
> _______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3
Bill Long longb at cray.com
Fortran Technical Suport & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101
More information about the J3
mailing list