def identity<T>(value: T): T {
return value;
}
def main(): int {
let number: int = identity(42);
let truth: bool = identity(true);
if (truth) { return number; };
return 1;
}عرف هوية<T>(القيمة: T): T {
أرجع القيمة;
}
عرف الرئيسية(): عدد {
دع الرقم: عدد = هوية(42);
دع الحقيقة: منطقي = هوية(صواب);
إذا (الحقيقة) { أرجع الرقم; };
أرجع 1;
}
Run it
With the interpreter, without compiling:
./build/sultanc run examples/en/generics/identity.snOr compile it to an executable:
./build/sultanc examples/en/generics/identity.sn -o build/example && ./build/example