Logo

Programming-Idioms

  • PHP
  • D
alias fun = (in a){return a * a;};

Using a delegate literal.
int square(int x) {
   return x*x;
}
declare(strict_types=1);
function square(int $x): int
{
    return $x * $x;
}

// square(4) -> 16
// square(3.4) -> Uncaught TypeError: Argument 1 passed to square() must be of the type int, float given
function Square (X : Integer) return Integer is
begin
   return X * X;
end Square;

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