[fpc-pascal] New feature: IfThen() intrinsic

Martin fpc at mfriebe.de
Tue Feb 2 19:10:19 CET 2016


On 02/02/2016 17:35, Marcos Douglas wrote:
> On Tue, Feb 2, 2016 at 3:06 PM, Martin <fpc at mfriebe.de> wrote:
>> In this case, I dislike the
>>     x := if a then b else c;
> Why not as below, using 'inline' keyword?
>
>     x := inline if a then b else c;
>
because it still resembles a statement.  (even so, I guess technically 
(with or without the inline, it actually is an operator, since its part 
of an expression)

And as pointed out the next would be "case of" or "inline case of".
Again, it makes no difference if the "inline" prefix turns the statement 
keyword into an operator, or if this change is deducted from the fact 
that it is in a right hand site expression.
The result is one more expression that looks like statements can return 
values (or at least statements prefixed by "inline").

Now the below might seem totally exaggerated, but if the above applies 
to "if" and "case" then really why should it end there? It certainly did 
not end there in C.

Whats next? codeblocks? (anonymous functions are on the way 
anyway(afaik), so this is not very different)
x := inline begin {any pascal code/list of statement}; result := value; end;
OUCH! (and caps dont even make that stand out enough)

Also there are many who want assignments
X := inline y := 1;
Now that might be looking nice if all you do is set 10 variables to 1.
But
x := inline if inline y := foo() > inline z := bar() then inline m:= 1 
else inline m:=2;
*OUCH*!!

-----------
about inlined codeblock (not that I would like it, but)

afaik anonymous functions may come in  a form like
    x := function begin {...} end; // which will also be a closure.
then that would allow
    x := function begin {...} end(); // calling in in place, and assign 
the result to x
which is really not much different to
    x := inline begin {...} end;

-----------
I would have as alternative to the function style prefered the operator 
without leading if (X:= a ifthen b ifelse c). But that requires new 
keywords, and will break a lot of code.
Basically anyone who has an identifier (variable, function, ...) called 
"ifthen"





More information about the fpc-pascal mailing list