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

Henry Vermaak henry.vermaak at gmail.com
Tue Feb 2 11:53:50 CET 2016


On Tue, Feb 02, 2016 at 11:24:57AM +0100, Michael Van Canneyt wrote:
> On Tue, 2 Feb 2016, Henry Vermaak wrote:
> 
> >On Tue, Feb 02, 2016 at 10:49:03AM +0100, Michael Van Canneyt wrote:
> >>So the iif in either functional or expression form has my vote.
> >
> >I'm surprised that you support iif in function call form.  Making
> >something that looks like a function call but may not behave as a
> >function call (short cut eval) seems like a recipe for disaster.
> 
> Would you mind explaining why ?

When you call a function all the arguments get evaluated before the
function gets called.  iif will look exactly like a function call, but
all the arguments may not be evaluated (that's the point, right).  This
is inconsistent and ambiguous, two things that pascal tries to eschew.

Even worse is that it's not a reserved symbol, so it can still be
overridden.  A call to iif in one unit may evaluate all its arguments,
while it may not in another unit.

Pascal is not a language full of programmer traps, let's try not to add
any!

Henry



More information about the fpc-pascal mailing list