Hi,
I found the merge statement as a ternary operator quite useful even when using it outside of its original scope of array assignments. One pitfall I've realized is the fact that even the code that is in the "false-branch" might be evaluated (similar to the Boolean operations in Fortran which are not short circuited). I'm however not sure about the following code, which I find quite useful for setting default arguments
program test implicit none real, parameter :: a = 5.0 real :: x real, dimension(:), allocatable :: y ! this is invalid, even if I ensure that y(1) exists in case that y is allocated ! because y(1) might be evaluated in the case that y is not allocated x = merge(y(1),a,allocated(y)) call hello(a) call hello() contains subroutine hello(b) implicit none real, intent(in), optional :: b real :: c ! what about this? c = merge(b,4.0,present(b)) write(6,*) c end subroutine hello end program