Logo

Programming-Idioms

  • PHP
  • Haskell

Idiom #294 Print a comma-separated list of integers

Given an array a containing the three values 1, 12, 42, print out
"1, 12, 42" with a comma and a space after each integer except the last one.

let a = [1, 12, 42] in
  putStrLn $ intercalate ", " (show <$> a)
with Ada.Text_IO;
declare
   A : array (1 .. 3) of Integer := (1, 12, 42);
begin
   for I in A'Range loop
      Ada.Text_IO.Put (A (I)'Image);
      if I /= A'Last then
         Ada.Text_IO.Put (", ");
      end if;
   end loop;
end;

New implementation...
< >
tkoenig