tags:

views:

59

answers:

3
+1  Q: 

Input in Nemerle

Hello, I want to know how to take input from the console of the form :

M 14 65 99 in nemerle. In C# I am doing this by :

            string[] input = System.Console.ReadLine().Split(' ');
            ch = System.Char.Parse(input[0]);
            a  = System.Int32.Parse(input[1]);
            d =  System.Int32.Parse(input[2]);
            m =  System.Int32.Parse(input[3]);

But this is not working in Nemerle. Please suggest me how to do it in Nemerle.

A: 

No responses ?! I know it's possible.

Perhaps you should say what is not working.
leppie
+3  A: 
class Test
{
  public static Main () : void
  {
    def input = System.Console.ReadLine ().Split (' ');
    def ch = System.Char.Parse (input[0]);
    def a  = System.Int32.Parse (input[1]);
    def d =  System.Int32.Parse (input[2]);
    def m =  System.Int32.Parse (input[3]);

    System.Console.WriteLine ("ch:{0} a:{1} d:{2} m:{3}",  ch, a, d, m);
  }
}
Matajon
+1  A: 

You can also use the IO macros:

using Nemerle.IO;
using System;

mutable ch, a, d, m;
try
{
    scanf("%c %d %d %d", ch, a, d, m);
    printf("%c %d %d %d\n", ch, a, d, m);
}
catch
{
    | _ is InvalidInput => Console.WriteLine("Invalid input")
}

Note, that unlike C++, Nemerle versions of printf and scanf are safe. They will only compile, if you pass parameters of the right type. In the above example, the correct types are even inferred from usage.

Don Reba