Logo

Programming-Idioms

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

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.

" Implementation: Visual Works "
| args arg sep |
args := CEnvironment commandLine readStream.
args next.    " skip executable name "
sep := [args peek isNil not ifTrue: [' '] ifFalse: ['']].
[ (arg := args next) isNil ] whileFalse: [
    Transcript show: arg; show: (sep value).
].
Transcript cr. " cr -> carriage return; ie. newline "

Needs to be run in headless mode so that Transcript prints to stdout.
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