Sign in Join

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

Mailing lists / fpc-other / 2016-02

Fwd: Re: New feature: IfThen() intrinsic

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

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

Martin

forwarding, as I read the "closed thread" notice only after this was written.

-------- Forwarded Message --------
Subject: Re: [fpc-pascal] New feature: IfThen() intrinsic Date: Tue, 2 Feb 2016 18:45:49 +0000
From: Martin
To: FPC-Pascal users discussions

Michael Schnell wrote 12 lines
On 02/02/2016 10:31 AM, Graeme Geldenhuys wrote: > Exactly! I'm glad somebody noticed that too. Of course I did notice :-) . V := If a < 3 then 1 else 2; In fact extends a several language paradigms: - a keyword (such as "if") returns a value - a statement (such as "if ....", and the content of an if clause ) returns a value

Actually, as Sven pointed out, it is not (supposed to be) a statement, but an expression.
Being an expression "a < 3", "1", "3" are the operands, therefore "if", "then", "else" (together) are an operator.

So the above should read
- a keyword used to start a statement, also can is used as an operator.

Also the if-then-else operator introduces a somewhat new syntax for an operator.
With the exception of unary operators ("-", "not"), operators are usually (in pascal) found between the operands.
The new operator however is found in front and between.

If it was not for (taking Sven's word for it / he wrote in another mail)

Sven Barth wrote 5 lines
Also in your second case especially the "ifThen" needs to be handled as an operator to avoid too big modifications of the parser that I don't see justified for something that should merely be a minor extension.

Omitting the "if" will mean much bigger changes to the compiler. I If I understand him correct, then in his opinion not worth it for the value of the feature.

The other problem of making it on operator that only goes between the operands is

     x:=  a>b  ifThen c ifElse b;

would mean that ifThen, ifElse will be new keywords. Breaking code, if someone uses them as identifier.

Though that could be solved:
     x:=  a>b  Then c Else b;

Reply by email