Part of the enjoyable challenge of learning Oxygene is trying to discover what is more C# (.Net/CLI) like or Object-Pascal like. Oxygene appears to have inherited quite a bit from .Net (understandably) such as integer division (10/3 = 3) vs returning a real number as Delphi/Lazarus FPC would do (10/3 = 3.333). Then I came upon the topic of operator precedence in the Oxygene online manual:
I read something similar as well in Marco Cantù’s book Essential Pascal :
Contrary to most other programming languages, the and and or operators have higher precedence than comparison ones. So if you write:
a < b and c < d
the compiler will do the and operation first, resulting in a compiler error. So you should enclose each of the < expressions in parentheses:
(a < b) and (c < d)
So I decided to run a quick test case in Delphi, Lazarus FPC, PascalABC.Net and Oxygene and all resulted in compiler errors except for … Oxygene.
namespace Oxy_precedence; interface uses System.Linq; type Program = class public class method Main(args: array of String): Int32; end; implementation class method Program.Main(args: array of String): Int32; begin var a := 10; var b := 12; var c := 5; var d := 8; // returns 'The magic happens here.' if (a < b) and (c < d) then writeLn('The magic happens here.') else writeLn('The magic is not here.'); // returns 'The magic is not here.' if a < b and c < d then writeLn('The magic happens here.') else writeLn('The magic is not here.'); end; end.
I was quite surprised that ’ a < b and c < d’ made it through Elements Compiler although it returned a dissimilar result than C#(Hydrogene).
Tests done using Fire .2667