Hi,
Is it possible to make this work:
if X > 3 or < 10 then ...
of course it would be shorthand for: if (X>3) or (X<10) then....
I suppose also it would be possible then to do:
if X > 3 or < -1 or = 4000 or = 1000000 then...
Andrew

Mailing lists / fpc-devel / 2007-12
9 messages · 8 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
Is it possible to make this work:
if X > 3 or < 10 then ...
of course it would be shorthand for: if (X>3) or (X<10) then....
I suppose also it would be possible then to do:
if X > 3 or < -1 or = 4000 or = 1000000 then...
Andrew
Not likely. See e.g. the FAQ about extensions:
http://www.freepascal.org/faq.var#extensionselect
"The extension must have real value. Anything that is only a shorter notation does not apply, unless it is out of compatibility with an existing Pascal/Delphi codebase. Practically it means it must make something possible that can't be done otherwise or be a compability item"
The main reason is that typing is never limiting (and typing optimization can be better solved with editor templates)
Is it possible to make this work: if X > 3 or < 10 then ... of course it would be…
One way to write this (assuming x is an integer type): if x in [4..9] then ...
I suppose also it would be possible then to do: if X > 3 or < -1 or = 4000 or = 1000000 then...
if x in [4..high(integer), low(integer)..-1, 4000, 1000000] thenVincnet
Is it possible to make this work: if X > 3 or < 10 then ... of course it would be…
The "or" operator is stronger than the "<" operator by definition. This can't be changed.
In C we have a logical or ("||") and a binary or ("|"), as there is no boolean type. In Delphi language there is only one operator "or", as the type defines the makeup of the operation. While this is nice, it prevents the "<" operator from being stronger that "or", as the "or" might be bitwise.
if X > 3 or < -1 or = 4000 or = 1000000 then...
for me
a or = 1000000;
should mean a := a or 1000000;:)
-Michael
In C the operators &, |, && and || *all* have lower precedence than ==, !=, <, >, <= and >=. (As a consequence, in C you probably want to use parenthesis in an expression like (mask & 0xF38A) == 0xF080.)
Though I also don't like the parenthesis in (X>3) or (X<10), I think it is not really a good plan to change the precedence of operators in FPC, since it encourages writing code that is not compatible with Pascal standards.
Regards,
Bram
The "or" operator is stronger than the "<" operator by definition. This can't be changed.…
Neither needs to be. There is no operand, but two operators ("or <") in the second expression, so you wouldn't even be able to apply precedence rules.
Vinzent.
Actually, the shorthand for this expression is
if true then
...
;)
Florian Klaempfl wroteActually, the shorthand for this expression is if true then ...
No, you mean:
(That is, nothing :) )
Micha
Indeed, but this would have been too hard to understand in one step ;)