# Basic Syntax

function f(x, y)
  x + y
end

println(f(2, 3))

g = f
println(g(2, 3))

# Pass by Sharing Function Behavior
arr = Int64[1, 2, 3]
i = 2

function h(x, i)
  x[i] -= 1
  i -= 1
end

println(h(arr, i));
println(arr);
println(i);

# Returning from a function

function divider(x, y)
  if (y != 0)
    return x / y
  end
  return "Divide by zero error!"
end

println(divider(1, 2))
println(divider(1, 0))

# Return a specific type

function divider(x, y) :: Int32
  if (y != 0)
    return x / y
  end
  return -1
end

# return nothing

function divider(x, y)
  if (y != 0)
    return x / y
  end
  return nothing
end

println(divider(1, 0))
println(typeof(divider(1, 0)));

# multiple Return Values with Tuples

function fun(x, y)
  x += 1
  y += 1
  x, y
end

println(fun(1, 2))
println(typeof(fun(1, 2)))

a, b = fun(1, 2)

# Operators are actually functions!

1 + 2 + 3

+(1, 2, 3)
-(4, 5)

# Anonymous functions
function (x)
  x^2 + 3x - 2
end

x -> x^2 + 3x - 2

println(map(x -> x^2 + 3x - 2, [1, 2, 3]))
