// الشريحة (`[] ق`) نافذة على تسلسل تأخذها الدوال وترجعها.
استورد std.io.println;
استورد std.text.number;
عرف المجموع_الكلي(القيم: [] عدد): عدد {
دع المجموع: متغير عدد = 0;
دع ف: متغير طبيعي = 0;
طالما (ف < (الطول(القيم) مثل طبيعي)) {
المجموع := المجموع + القيم[ف];
ف := ف + 1;
}
أرجع المجموع;
}
عرف الرئيسية(): عدد {
دع القيم: [] عدد = [10, 20, 12];
اطبع_سطر(عدد_إلى_نص(المجموع_الكلي(القيم)));
أرجع 0;
}// A slice (`[] T`) is a view of a sequence that functions can take and return.
import std.io.println;
import std.text.number;
def sum(values: [] int): int {
let total: mutable int = 0;
let i: mutable uint = 0;
while (i < (length(values) as uint)) {
total := total + values[i];
i := i + 1;
}
return total;
}
def main(): int {
let values: [] int = [10, 20, 12];
println(int_to_text(sum(values)));
return 0;
}
التشغيل
بالمفسر، دون ترجمة:
./build/sultanc run examples/ar/collections/slices.snأو ترجمه إلى ملف تنفيذي:
./build/sultanc examples/ar/collections/slices.sn -o build/example && ./build/example