Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2007-12

weird syntax

9 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Andrew Haines

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

Reply by email

Marco van de Voort
to Andrew Haines
Show quoted text 9 lines
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...

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)

Reply by email

Vincent Snijders
to Andrew Haines: Is it possible to make this work: if X > 3 or < 10 then ... of course it would be…
Andrew Haines wrote 8 lines
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....

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] then

Vincnet

Reply by email

Michael Schnell
to Andrew Haines: Is it possible to make this work: if X > 3 or < 10 then ... of course it would be…
Andrew Haines wrote 9 lines
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....

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

Reply by email

Bram Kuijvenhoven
to Michael Schnell
Michael Schnell wrote 14 lines
Andrew Haines wrote: > 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.... > 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.

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

Reply by email

Vinzent Hoefler
to Michael Schnell: The "or" operator is stronger than the "<" operator by definition. This can't be changed.…
Michael Schnell wrote 12 lines
Andrew Haines wrote: > 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.... 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.

Reply by email

Florian Klaempfl
to Vinzent Hoefler
Show quoted text 16 lines
On Tuesday 11 December 2007 10:04, Michael Schnell wrote: > Andrew Haines wrote: >> 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.... > 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.

Actually, the shorthand for this expression is
if true then
...
;)

Reply by email