0Pricing
Mojo Academy · درس

قراءة توقيعات الدوال

افهم الدالة من تصريحها

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

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

The Signature Is the Contract

A function's signature is its first line: the name, the parameters, and the return type. Read it well and you know how to call the function.

fn area(width: Int, height: Int) -> Int:

Spotting the Name

Right after fn or def comes the name. It should hint at what the function does, like area, parse, or connect.

fn parse(text: String) -> Int:

Reading the Parameters

Inside the parentheses are the parameters the function expects. Each pairs a name with a type, telling you what to pass in.

fn area(width: Int, height: Int) -> Int:

Parameter Types Guide You

The type after each colon tells you the kind of value to send. width: Int means area expects a whole number, not text.

fn greet(name: String, times: Int): ...

The Return Type Arrow

The arrow points to what the function gives back. Here -> Int promises an integer result you can store or print.

fn area(width: Int, height: Int) -> Int:

No Arrow Means No Value

When there is no arrow, the function returns None. It does its work for the side effect, like printing, not for a result.

fn log(msg: String):
    print(msg)

Defaults in the Signature

An equals sign in a parameter marks a default. It signals the value is optional and shows the fallback Mojo will use.

fn open(path: String, mode: String = "r"): ...

raises Warns of Failure

A raises keyword on the signature means the function can fail. That tells you to wrap your call in error handling.

fn read(path: String) raises -> String:

fn vs def at a Glance

The opening word matters. fn means strict and typed; def means flexible and Python-like. The signature tells you which contract you are under.

def loose(x): ...
fn strict(x: Int) -> Int: ...

A Signature as Mini-Docs

Before reading any body, the signature already answers what goes in and what comes out. Treat it as the function's summary.

Putting It All Together

Name, parameters, defaults, return type, and raises: each part of the signature is a clue. Together they tell you exactly how to use the function.

fn fetch(url: String, retries: Int = 3) raises -> String:

Quick Check

In a Mojo signature, what does the part after the arrow tell you?

Recap: Read Before You Call

A signature shows the name, parameters with types, any defaults, the return type, and raises. Read it first and calling correctly becomes easy.

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

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

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

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

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

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

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

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

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

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

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

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

  1. الوسيطات الموضعية والمسمّاة
  2. القيم الافتراضية للوسيطات
  3. إرجاع قيم متعددة
  4. قراءة توقيعات الدوال
← العودة إلى Mojo Academy