Michael Van Canneyt wrote:
On Thu, 8 Oct 2015, Sven Barth wrote:
Am 08.10.2015 19:10 schrieb "Ralf Quint" <[email protected]>:
On 10/8/2015 9:54 AM, Sven Barth wrote:
I had the idea to implement inline-if as well. I think the syntax I
selected is derived from Oxygene, but it looks very Pascal and shouldn't
break anything:
left := if expr1 then expr2 else expr3;
Thereby expr1 returns Boolean and expr2 determines the type of the
whole
inline-if, thus expr3 needs to be compatible to expr2.
Sorry, but that doesn't "look Pascal" at all, and is anything but easily
understandable, specially given the possible complexity of expr[1,2,3]...
And you think C's ternary would be more Pascal? Also you need /some/
definition of what defines the type no whether what syntax you choose (in
addition expr1 is the same as in normal ifs, so it's only the
"complexity"
of expr2 and expr3). And no, "the left side" is not the Pascal answer
either.
Actually, yes I think C's or Javascript's ternary is better suited.
Let me explain. If I see
If expr1 then expr2 else expr3
it says 'statement' to me. But
a ? b : c;
Says "expression" to me.
So
left := a ? b : c;
OK. So presumably, since false < true, b is executed if a is false and c
is executed if it's true? >:-)
looks more 'right' than the 'if then else', because the right-hand side
is clearly an expression.
The "if expr1 then expr2 else expr3" is equally counter-intuitive and
confusing as anonymous functions.
Keyword "If" starts a statement. If you allow to use it in expressions,
its meaning becomes context sensitive. That is a bad thing in my book.
So if this thing needs to be implemented, then I'd much prefer it in the
ternary form.
The way I look at it is that it's restoring a feature that was (possibly
accidentally) dropped during the ALGOL -> Pascal transition. As such I
don't have any problem with ALGOL-style
left := if a then b else c;
After all, while concise C-style operators work well in expressions this
is not a simple expression where all components are evaluated: it's
directly equivalent to the statement-level if potentially including
exactly the same short-circuiting rules in the boolean expression (a above).
The thing I do have problems with is the difficulty people had
explaining nested inline ifs during the 1960s. However I think that was
more because they simply hadn't worked out how to write language
documentation rather than there being anything inherently tricky about
it, and these days there's absolutely no reason why it shouldn't be
spaced and indented in a thoroughly Pascal-like fashion :-)
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-devel maillist - [email protected]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel