Programming-Idioms

This language bar is your friend. Select your favorite languages!

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.

use std::env;
println!("{}", env::args().skip(1).collect::<Vec<_>>().connect(" "));
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;
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
    while (*++argv) {
        printf("%s", *argv);
        if (argv[1]) printf(" ");
    }
    printf("\n");
    return EXIT_SUCCESS;
}
(println (clojure.string/join " " *command-line-args*))
#include <iostream>
int main(int argc, char * argv[])
{
	for(int i = 1; i < argc; ++i)
	{
		std::cout <<(1==i ? "" : " ") << argv[i];
	}
        std::cout <<std::endl;
}
using System;
public class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine(string.Join(" ", args));
    }
}
import std.stdio : writeln;
import std.algorithm.iteration : joiner;
import std.range : dropOne;
void main(string[] args)
{
	writeln(args.dropOne.joiner(" "));
}
import std.string, std.stdio;
void main(string[] args)
{
	args[1..$].join(" ").writeln;
}
main(List<String> args) {
  print(args.join(' '));
}
Enum.join(args, " ")
-module(echo).
-export([main/1, main/0]).
main() ->
    main(init:get_plain_arguments()).

main(ARGV) ->
    io:format("~s~n", [lists:join(" ", ARGV)]).
program x
  implicit none
  character (len=:), allocatable :: a
  integer :: n, i, l
  n = command_argument_count()
  a = ''
  do i=1,n
     call get_command_argument(i, a, l)
     if (l > len(a)) then
        deallocate (a)
        allocate (character(len=l) :: a)
        call get_command_argument(i, a)
     end if
     write (unit=*,fmt='(A)', advance="no") a
     if (i < n) then
        write (unit=*,fmt='(" ")', advance="no")
     else
        write (unit=*,fmt='()')
     end if
  end do
end
package main
import "fmt"
import "os"
import "strings"
func main() {
    fmt.Println(strings.Join(os.Args[1:], " "))
}
import System.Environment
putStrLn . unwords =<< System.Environment.getArgs
console.log(process.argv.slice(2).join(" "));
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));
    }
}
fun main(args: Array<String>) = args.forEach(::println)
(format t "~{~A~^ ~}~%" *args*)
print( table.concat( arg, " " ) )
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
    while (*++argv) {
        printf("%s", *argv);
        if (argv[1]) printf(" ");
    }
    printf("\n");
    return EXIT_SUCCESS;
}
echo implode(' ', array_slice($argv, 1)), PHP_EOL;
PROGRAM Echo;

VAR
    I: Integer;
BEGIN
    for I := 1 to ParamCount - 1 do
        Write(ParamStr(I), ' ');
    if (ParamCount > 0) then
        Write(ParamStr(ParamCount));
    WriteLn();
END.
print "@ARGV\n"
main(Argv) :- echo(Argv).

echo([]) :- nl.
echo([Last]) :- write(Last), echo([]).
echo([H|T]) :- write(H), write(' '), echo(T).
import sys
print ' '.join(sys.argv[1:])
puts ARGV.join(' ')
printf("%s\n", ARGV.join(' '))
println(args.mkString(" "))
(display (string-join (list-tail (command-line) 1) " "))
(newline)

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

christianhujer