C# to Oxygene Multiple Input code translation

I’m looking to translate this C# algorithm to Oxygene. It’s for receiving multiple integer inputs to be added together since the readLn() function in Oxygene is not a variadic function like it is in Delphi/FPC (eg. readLn(name, age) ). It works as expected in Hydrogene.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace sumInputsMulti;
{
    static class Program
    {
        public static void Main(string[] args)
        {
            write("Enter integers separated by a space to add: ");
            //Console.WriteLine(Console.ReadLine().Split().Select(int.Parse).Sum());   // original C# code
            writeLn(readLn().Split().Select(int.Parse).Sum()); //  added some Pascal syntax flavor :)

            writeLn("Enter any key to exit..."); 
            readLn();                            

        }
    }
}

But when I translate this to Oxygene, I’m getting a “No Matching Overload” error tied to ‘Int32.Parse’. The C# code uses ‘int’ which is not part of Oxygene’s vocab. But I understand that ‘int’ is equivalent to ‘Int32’.

namespace sumInputsMulti;

interface


Uses System,
     System.Linq;


type
  ConsoleApp = class
  public
    class method Main();
  end;

implementation

class method ConsoleApp.Main();
begin
   writeLn(readLn().Split().Select(Int32.Parse).Sum());  // No matching overload error

   writeLn("Enter any key to exit..."); 
   readLn();                                                        
end;

end.

Both are geared for NetCore if that makes any difference. Any insight on how I could make this work in Oxygene would be much appreciated. :nerd_face:

As an aside, why is the C# syntax highlighting so colorful and Oxygene’s is so colorless and lifeless … hold on, I see that ‘Sum’ is highlghted. So there’s a little sign of life.

Curious. it seems that in C# you can pass the actual method as a closure, but in Oxygene you cannot, without making that explicit — probably because it’s a bit ambiguous with Oxygene not needing () for the call, as C# does.

these two versions will work:

writeLn(readLn().Split().Select(@Int32.Parse).Sum());

and

writeLn(readLn().Split().Select(s -> Int32.Parse(s)).Sum());
1 Like

Awesome Marc! Cheers :fist_right: :fist_left:

1 Like