这个就是用来给返回值换一个名字。
比如:
FUNCTION GetSomeData( someinput ) RESULT( ans )
ans = f( someinput )
end function GetSomeData
如果你不写 result(ans)的话,你必须写成
GetSomeData = f( someinput )
这样看起来不好看。实际上,最重要的应用,在于递归调用函数时,给出最终递归结果。
参考帮助文档:
RESULT
Keyword: Specifies a name for a function result.
Normally, a function result is returned in the function’s name, and all
references to the function name are references to the function result.
However, if you use the RESULT keyword in a FUNCTION statement,
you can specify a local variable name for the function result. In this case, all
references to the function name are recursive calls, and the function name must
not appear in specification statements.
The RESULT name must be different from the name of the function.
Compatibility
CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB
See Also: FUNCTION, ENTRY, RECURSIVE, Program Units and Procedures
Examples
The following shows an example of a recursive function specifying a
RESULT variable:
RECURSIVE FUNCTION FACTORIAL(P) RESULT(L)
INTEGER, INTENT(IN) :: P
INTEGER L
IF (P == 1) THEN
L = 1
ELSE
L = P * FACTORIAL(P - 1)
END IF
END FUNCTION
The following shows another example:
recursive function FindSame(Aindex,Last,Used) & !Recursive(递归的)
& result(FindSameResult)
type(card) Last
integer Aindex, i
logical matched, used(5)
if( Aindex > 5 ) then
FindSameResult = .true.
return
endif