Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
fn square(x : u32) -> u32 { x * x }
function Square (X : Integer) return Integer is
begin
   return X * X;
end Square;
int square(int x){
  return x*x;
}
let square x = x*x
(defn square [x]
  (* x x))
int square(int x){
  return x*x;
}
void Square(ref int x)
{
    x = x * x;
}
int Square(int x)
{
    return x * x;
}
double Square(int value) => System.Math.Pow(value, 2);
int Square(int x) => (int)Math.Pow(x, 2);
alias fun = (in a){return a * a;};
int square(int x) {
   return x*x;
}
int square(int x) => x * x;
@spec square(integer) :: integer
def square(x) when is_integer(x), do: x*x
-spec square(integer()) -> integer().
square(X) when is_integer(X) -> X * X.
module foo
  implicit none
contains
  function square(i) result(res)
    integer, intent(in) :: i
    integer :: res
    res = i * i
  end function square
end module foo
func square(x int) int {
  return x*x
}
int square(int x){
  return x*x
}
square x = x * x
square x = x**2
square x = x^2
const square = (x) => x * x;
function square(x) { 
	return x * x;
}
const square = (number) => Math.pow(number, 2);
const square = n => n**2
Function<Integer,Integer> squareFunction = x -> x * x;
import java.math.BigInteger;
BigInteger square(BigInteger a) {
    return a.multiply(a);
}
interface F { int get(int a); }
F square = x -> x * x;
import static java.lang.Math.pow;
int square(int a) { return (int) pow(a, 2); }
int square(int x){
  return x*x;
}
int square(int a) { return a * a; }
fun square(x: Int) = x * x
(defun square (x)
  (* x x))
function square(x)
	return x*x
end
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): Integer;
Begin
  Result := x*x;
End;
sub square {
    my ($i) = @_;
    return $i ** 2;
}
square = lambda x: x * x
def square(x):
    return x**2
def square(x):
    return x*x
def square(x)
  x*x
end
def square(x) = x*x
def square(x:Int): Int = x*x
(define square
    (lambda (x)
        (* x x)))
(define (square x)
    (* x x))
[:anInteger | anInteger squared]
Function Square(x As Integer) As Integer
    Return x * x
End Function
Function Square(x As Integer) As Double
    Return x ^ 2
End Function

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