Logo

Programming-Idioms

  • Lua
  • Pascal
  • Rust
  • C
  • Go

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 "fmt"
import "os"
import "strings"
func main() {
    fmt.Println(strings.Join(os.Args[1:], " "))
}
print( table.concat( arg, " " ) )
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.
use itertools::Itertools;
println!("{}", std::env::args().skip(1).format(" "));
use std::env;
println!("{}", env::args().skip(1).collect::<Vec<_>>().join(" "));
#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;
}
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