Logo

Programming-Idioms

  • Scheme
  • Java
  • Haskell

Idiom #71 Echo program implementation

Basic implementation of the Echo program: Print all arguments except the program name, separated by space, followed by newline.
The idiom demonstrates how to skip the first argument if necessary, concatenate arguments as strings, append newline and print it to stdout.

import System.Environment
putStrLn . unwords =<< System.Environment.getArgs
(display (string-join (list-tail (command-line) 1) " "))
(newline)
import static java.lang.String.join;
import static java.lang.System.out;
class Echo {
    public static void main(String[] args) {
        out.print(join(" ", args));
    }
}
import static java.lang.String.join;
import static java.lang.System.out;
public class Echo {
    public static void main(final String... args) {
        out.println(join(" ", args));
    }
}

String.join() exists only since Java 8.
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
begin
   for I in 1 .. Argument_Count loop
      Put (Argument (I) & (if I = Argument_Count then "" else " "));
   end loop;
   
   New_Line;
end Main;

New implementation...
< >
christianhujer