0Pricing
Mojo Academy · درس

استعارة الوسيطات للقراءة فقط

الاستعارة هي الخيار الافتراضي للقراءات الآمنة

استعارة الوسيطات للقراءة فقط درس مجاني في Mojo Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Mojo Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Mojo Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Why Ownership Matters

When you pass a value to a function, Mojo needs to know who can read or change it. That rule is an ownership convention. 🔑

The Default Is Borrowing

By default an argument is borrowed. The function gets read access to the caller's value but does not take it over.

Read, Don't Modify

A borrowed argument is read-only inside the function. You can look at it freely, but Mojo will not let you change it.

No Copy Needed

Borrowing avoids copying the data. The function shares the caller's value as an immutable reference, which keeps things fast.

Spelling It Out

You can write borrowed before a parameter to be explicit, though it is already the default for an fn function.

fn area(borrowed w: Int, borrowed h: Int) -> Int:
    return w * h

The Same Without the Keyword

Because borrowing is the default, you usually skip the keyword. This function reads its argument exactly the same way.

fn area(w: Int, h: Int) -> Int:
    return w * h

Trying to Mutate Fails

If you assign to a borrowed argument, the compiler stops you. That error is Mojo protecting the caller's value.

Safe to Share

Because the function only reads, you can borrow the same value in many calls at once with no risk of a surprise change.

Great for Big Data

Borrowing shines when a value is large. You read a big struct without paying the cost of a full copy on every call.

Caller Keeps Ownership

After a borrowed call, the original variable is still valid and unchanged. The caller never lost ownership of its value.

The Safe Read Default

Borrowing is Mojo's safe, efficient default: read access, no copy, no mutation. Reach for it whenever a function only needs to inspect data.

Quick Check

Let us test what a borrowed argument allows.

Recap

Borrowing is the default: the function reads the caller's value with no copy and no mutation. It is Mojo's safe, fast way to pass data. 🎯

الأسئلة الشائعة

هل درس «استعارة الوسيطات للقراءة فقط» مجاني؟

نعم — نص درس «استعارة الوسيطات للقراءة فقط» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Mojo Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Mojo Academy 4 دروس في المجموع.

ماذا ستتعلم في «استعارة الوسيطات للقراءة فقط»؟

الاستعارة هي الخيار الافتراضي للقراءات الآمنة تتمرن على Mojo Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Mojo Academy؟

لا تُشترط خبرة سابقة. Mojo Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «استعارة الوسيطات للقراءة فقط»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Mojo Academy هذا؟

نعم. كل درس في Mojo Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. استعارة الوسيطات للقراءة فقط
  2. التغيير في المكان باستخدام inout
  3. تولّي الملكية باستخدام owned
  4. عامل النقل
← العودة إلى Mojo Academy