[fpc-pascal] evaluation of set constant
Torsten Bonde Christiansen
tc at epidata.dk
Thu Dec 23 10:14:30 CET 2010
On 2010-12-22 14:50, Jonas Maebe wrote:
> On 22 Dec 2010, at 14:15, Torsten Bonde Christiansen wrote:
>> Is it possible to create a constant of a set that is based on an
>> evaluation of other constants? (using fpc 2.4.2)
>> A basic case could look like this:
>> TMyType = (a, b, c ,d);
>> TMyTypes = set of TMyTypes;
>> SetX: TMyTypes = (a, b);
>> SetY: TMyTypes = (c, d);
> These definitions should not compile, a set is defined as [a, b], not
> (a, b).
Sorry - that was my bad, i just made a typo in the previous email. It's
written with  in my code.
>> SetCombined: TMyTypes = SetX + SetY; // this gives me an "Error:
>> Illegal expression"
>> I have been reading throught the FPC docs, but it is unclear whether
>> this is possible at all. The set operators allow this and according
>> to FPC doc section on constants some expression evaluation is possible.
> So-called "typed constants" are actually initialised variables (for
> historical reasons). The compiler cannot evaluate expressions that
> involve variables (initialised or not).
> Change the constants into symbol constants if you want to use them in
> constant expressions:
> SetX = [a, b];
> SetY = [c, d];
> SetCombined = SetX + SetY;
Ahh... great. I never thought of the difference between typed constants
and symbol constants. Now it works, Thank!
Torsten Bonde Christiansen.
More information about the fpc-pascal