Skip to content

Initial draft of conditional expression intrinsic paper #213

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

Merged
merged 13 commits into from
Jun 27, 2021
34 changes: 34 additions & 0 deletions proposals/conditional_expressions/cond.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
To: J3 J3/XXX
From: Ondrej Certik
Subject: Conditional expressions using intrinsic function
References: 21-157, 21-159
Date: 2021-June-26

Paper 21-157 proposes two syntactic forms for
conditional expressions. The paper 21-159 proposes
an alternative form. This paper proposes to implement
conditional expressions using intrinsic functions

The syntactics forms in 21-157 is too verbose, as argued in 21-159. The form in
21-159 is concise, but based on the poll [1], it is not the most popular
either.

We propose the following syntactic form

<cond-expr> is ifthen( predicate, consequent,
[ ifthen( predicate, consequent, ]*
alternative) [)]*

where the predicates are scalar logical expressions
and the consequents and alternative are compatible
expressions. The number of `)` must match the number of `ifthen(` used.

Examples:

ifthen(x >= 0.0, sqrt(x), -0.0)

ifthen(present(x), a, ifthen(present(b), b, 0))

References:

[1] https://fortran-lang.discourse.group/t/poll-fortran-202x-conditional-expressions-syntax/1425