-
Notifications
You must be signed in to change notification settings - Fork 17
Conditional Expressions #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The proposed syntax in CALL SUB(A,B,C,IF (PRESENT(D)) THEN (D) ELSE IF (X<1) THEN (EPSILON(X)) ELSE (SPACING(X)) END IF) Here is how Python does it: https://docs.python.org/3/reference/expressions.html#conditional-expressions |
Dear @certik , I agree that short-circuit conditional evaluation could be an interesting feature. On the other hand, Fortran provides the merge instrinsic that, I think, it covers the example (quoted) below (usually called ternary operator):
|
Short circuit conditionals might alleviate a lot of segmentation faults; I know this would have saved my hide a few times. |
@victorsndvg, @zbeekman thanks for the feedback. Note that this particular proposal began long before my time at the committee and I don't feel very strongly either way on this particular one. I am watching what the committee works on and discusses and I am trying to create issues here for each proposal, to track it and to enable discussions with the wider community outside the committee. |
Yes weighing in here with community feedback! Thanks for doing this @certik! I'd love to see J3 put more proceedings/documents/etc. on GitHub or GitLab. |
The difference with merge is 1) merge may evaluate all options regardless of the logical expression and 2) merge returns values, not variables. So Though short-circuiting logical expressions appeared in the initial paper, it isn't really being pursued here. Which is unfortunate; I'm much more interested in short-circuiting logical expressions than conditional expressions. |
Latest syntax paper: https://j3-fortran.org/doc/year/19/19-247r1.txt The main feedback from the committee seems to be that the conditional expression proposal above does not make things much simpler or clearer, and the new syntax does not seem appealing. The alternative is to short-circuit logical expressions, so this: IF (I<N .AND. A(I)==0) ... could be written, e.g., as: IF (I<N .ANDTHEN. A(I)==0) ... That way the old (There is also an option to make |
Initial recent paper: https://j3-fortran.org/doc/year/18/18-274.txt (there is a long history of trying to get something like this standardized).
Motivation
Citing from the paper:
People have wanted to write things like
for decades. So far, we have fobbed them off and they have to write
which is not just verbose but less convenient when wishing to test a series
of conditions.
Similarly, writing
is verbose but usable when only one argument is conditional, but rapidly
degenerates when there are several arguments requiring similar handling.
The text was updated successfully, but these errors were encountered: