Conditional expressions
Tom Verhoeff
wstomv at win.tue.nl
Tue Jan 2 12:01:15 CET 2001
>Peter and I are discussing the possibility of including some kind of
>conditional operator, like `foo ? bar : baz' in C. Since GPC uses
>GCC's backend, this should be easy to do semantically, the main
>question is about syntax:
I would like to propose the following syntax:
<expr> if <cond> else <expr>
This is concise and nice (you can view "if <cond> else" as infix operator).
Disadvantage: it requires priorities/parentheses for proper binding,
it uses the if/else, which also appears in the conditional statement
(this is also an advantage, since it does not require new reserved
words/symbols).
This syntax (not the sugar) is preferred by Tony (sir C.A.R.) Hoare in
Unifying Theories of Programming
C.A.R. Hoare and He Jifeng
Prentice-Hall, 1998
Hoare uses sugar with a left-pointing open triangle instead of "if"
and a right-pointing open triangle instead of else:
( Expr1 <| Cond |> Expr2 )
I do not think this is a very "urgent" extension (but it would have
been nice if it had been taken up in some standard).
Tom Verhoeff
More information about the Gpc
mailing list