I was pleasantly surprised to discover that the dec() method can accept types other than integers/ordinals like Delphi/Object Pascal. I wrote the following code in several languages to test the BigDecimal and Decimal types by decrementing to 0 using Real numbers. As you know Float and Double types are not accurate enough to reach absolute 0:
namespace DecimalType_Oxy;
begin
var x: Decimal := 1.0; // C#: var x = 1.0m; 'm' indicates 'Decimal' type
const decr: Decimal = 0.1;
const zero: Decimal = 0.0;
while x ≥ zero do
begin
writeLn(x);
x := x - decr;
end;
end.
It works as expected with the following output:
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.0
But I thought I might attempt to implement more idiomatic Pascal syntax by using the dec() method instead:
namespace DecimalType_Oxy;
begin
var x: Decimal := 1.0;
const decr: Decimal = 0.1;
const zero: Decimal = 0.0;
while x ≥ zero do
begin
writeLn(x);
dec(x, decr);
end;
end.
But this version will lock up the Fire IDE and must be force quit. So, is it reasonable to assume that the dec() method probably does not accept the Decimal type? Thanks for looking!
Reverting to a smaller program which shows that the y variable is never read when using the dec() method. The program compiles but with the unexpected output of 5.5. The statement x := x - y; works as expected.
Ah yes. and reproduced. Fire really does not like 500k messages being dumped to the console log at once. I’ll need to find a good solution to prevent it locking up on that, w/o actually allowing the debug log to grow, literally, infinite…
I’ll log an issue to fix that and one for dec() – if it doesnt work with Decimal, it should not compile.
Thanks for looking Marc! As an aside, have you and/or your team members ever considered adopting the m literal suffix for Oxygene, Mercury… allowing the compiler to infer the type from m vs explicit type annotation?
So we could write: var num1 := 1.23m
versus var num1:Decimal := 1.23; or var num1 := Decimal(1.23);
In some scenarios, 1.0m and 0.0m could effectively replace accessing fields Decimal.one and Decimal.zero.
Not to sway you all one way or another, but the computer scientist university professors who created the cousin CLI-based Pascal is seriously considering adopting the m suffix for the Decimal type.
no arguent that a shorter syntax woukld be nice. but a letter suffix is orthogonal too how all other Pascal numerals work, and its a straight lift from C(#).
2909 has some mitigations for “too much logging”. but endless too-fast logging will still make you sad. though chances are if you press Stop it will react eventually, now, rather than never. A proper fix will probably need cooperation with the debug engine itself.
Looks work on this is ongoing today, so probably will be in coming Friday’s build.
See … this is what happens, Marc, when you try and do the right thing and maintain Pascal constructs like dec() and succ() in Oxygene instead of going with .Net syntax: -= and +=
id actually like to see support += and -= at some point (especially since w have them anyways, for events). just haven’t gotten around to logging that yet…
So, is this fix mainly to prevent an endless loop? I tested the use of dec() with the Decimal type and although the code compiles, the output is not as expected. It looks like the y variables is never read and simply bypassed?: