### Перегрузка по типу
fn func(let param : int)
{
print("int");
}
fn func(let param : string)
{
print("str");
}
func(10); // int
func("s"); // str
fn func(let param : int = 10)
{
print(param);
}
func(); // 10
func(10); // 10
func(15); // 15
Дефолтное значение может иметь любой параметр,
но если мы пропускаем параметр нам надо явно это отметить
символом _
fn func(let a = 10, let b = "s")
{
log::info(a,b);
}
func( 5 , "b" ); // 5 b
func( 5 ); // 5 s
func( _ , "b" ); // 10 b
func( _ , _ ); // 10 s
func(); // 10 s
Мы можем отделить одни параметры от других символом ;
В пределах группы будут свои дефолтные значения.
fn func(let a = 1, let b = 2; let a2 = 3, let b2 = 4)
{
log::info(a, b, a2, b2);
}
func(); // 1 2 3 4
func(;); // 1 2 3 4
func(10, 20); // 10 20 3 4
func(; 30, 40); // 1 2 30 40
func(10; 30); // 10 2 30 4
func(10, 20; 30, 40) // 10 20 30 40
fn func() -> (let : string)
{
return "abc";
}
fn func() -> (let : int)
{
return 100;
}
let const funcResult1 = func()->int; // 100
let const funcResult2 = func()->string; // "abc"
fn func2(let param : int) -> (let : type(param))
{
return param + 10;
}
fn func2(let param : string) -> (let : type(param))
{
return param + "c";
}
let const funcResult1 = func2(10); // 20
let const funcResult2 = func2("ab"); // "abc"
fn func3(let param) -> (let : type(param))
{
return param * 10;
}
let const funcResult1 = func2(10); // 100
let const funcResult2 = func2(10.0); // 100.0
fn func3(let param) -> (let)
{
return param * 10;
}
let const funcResult1 = func2(10); // 100
let const funcResult2 = func2(10.0); // 100.0
fn func3(let copy param)
{
print("1");
}
fn func3(let mut ref param)
{
print("2");
}
fn func3(let const ref param)
{
print("3");
}
fn func3(let rref param)
{
print("4");
}
let mut a = 10;
let const b = 15;
func3(copy a); // 1
func3(ref a); // 2
func3(ref b); // 3
func3(ref const a); // 3
func3(5); // 4
fn func(::)
{
}