[fpc-devel] new features and facilities

Mark Morgan Lloyd markMLl.fpc-devel at telemetry.co.uk
Sat Oct 10 13:12:41 CEST 2015


Michael Van Canneyt wrote:
> On Sat, 10 Oct 2015, Sven Barth wrote:
> 
>> Am 10.10.2015 10:51 schrieb "Mark Morgan Lloyd" <
>> markMLl.fpc-devel at telemetry.co.uk>:
>>>
>>> Michael Van Canneyt wrote:
>>>>
>>>> On Fri, 9 Oct 2015, Sven Barth wrote:
>>>>
>>>>
>>>>>>
>>>>>> I'm not sure this kind of semantics is possible with a compiler
>>>>>
>>>>> intrinsic...
>>>>>>
>>>>>> But if it is: In that case the IfThen or IIF() or somesuch has my
>>>>>
>>>>> absolute top preference, followed by ternary. (and the If .. then
>>>>> expression should be blasted to hell ;) )
>>>>>
>>>>> Yes a compiler intrinsic could handle that. In the end all three
>> syntaxes
>>>>> are the same code representation anyway: namely an if-node.
>>>>> The IfThen() intrinsic would be fine with me as well. Let's call this
>> our
>>>>> common ground ;)
>>>>
>>>>
>>>>
>>>> Agreed !
>>>
>>>
>>> It would be even better if it could be generalised to evaluate and 
>>> return
>> one of any number of expressions.
>>
>> How do you think that could look like? IfThen() is the wrong intrinsic 
>> for
>> this and for a CaseOf() intrinsic you'd nevertheless need the case 
>> labels.
>> And /then/ I agree with Ralf that it isn't understandable...
> 
> I had the same thought. The only case I see applicable is an ordinal.
> CaseOf(a, ord(a)=0, ord(a)=1, ord(a)=2...)
> Still it seems somewhat convoluted.

Two possibilities that I can see. The first would be a variable or 
expression followed by an array of corresponding expressions, implicitly 
zero-based:

left := CaseOf(a, [b, c, d]);

The second would be an array of tuples, each a predicate followed by an 
expression, with the predicates evaluated left-to-right until one is true.

In either case there would have to be explicit rules as to what happened 
if the variable was out of range or no predicate evaluated true: I don't 
know whether it would be feasible to have a final optional flags element 
to determine this sort of thing, or if this is moving too far from what 
could reasonably be called a syntax structure.

One thing that bothers me about these approaches is that sooner or later 
some awkward cuss (such as myself) will start whining about how much 
better Pascal would be if there were a decent macro preprocessor so that 
CaseOf() could be specialised into other forms expressing choice :-/

I'd add that historically, extended ALGOLs had if-then-else inline but 
put anything with more elements (e.g. tables of labels) into the 
declarations at the start of a block. However my reading of the manuals 
suggests that they might have been inconsistent about whether the first 
element was indexed 0 or 1.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-devel mailing list