Logo

Programming-Idioms

  • Elixir
  • D
import std.stdio : writeln;
import std.range : iota;
import std.algorithm.iteration : each;
iota(0,10).each!(a => "Hello".writeln);

iota generates an iterable sequence of number.
each is a higher order function.
Hello is written using UFCS in a delegate literal.
import std.stdio;
foreach(i; 0..10)
  writeln("Hello");

use foreach with a numeric range instead of for whenever possible to avoid subtle errors. Also allows nice type inferrence.
1..10 |> Enum.each(fn _ -> IO.puts "Hello" end)

The pipe operator is very common in elixir and is used to chain function calls
with Ada.Text_IO;
use Ada.Text_IO;
for I in 1 .. 10 loop
  Put_Line ("Hello");
end loop;

New implementation...
< >
programming-idioms.org