Skip to content
العربية

12. Modules

To import a standard module and use its functions.

  • A module is a .م file you import into your program. The standard library is the set of modules that come with the compiler.
  • Write استورد رياضيات (import math) at the top of the file, then call its functions like this: رياضيات.جذر(81.0), that is, the module name, a dot, then the function name.
Example
استورد رياضيات
اطبع(رياضيات.جذر(81.0), " ", رياضيات.نسق(رياضيات.باي, 2))
Output recorded in the reference handbookmeem برنامج.م · 0.17.1
9.0 3.14

Try this example in the playground

Importing a module that does not exist:

Causes the error
استورد وحدة_لا_وجود_لها
Output recorded in the reference handbookmeem برنامج.م · 0.17.1
​[خطأ دلالي E0167] سطر 1:1 - الوحدة 'وحدة_لا_وجود_لها' غير موجودة   1 | استورد وحدة_لا_وجود_لها     | ^~~~~~  ملاحظة: بُحث عنها في: المكتبة القياسية، وحدة_لا_وجود_لها.م، مكتبات/وحدة_لا_وجود_لها.م  تلميح: تأكد من اسم الملف ومن وجوده بجوار هذا الملف.

Exit code: 2

In the error catalog: E0167

Write a function مسافة (distance) between two points using رياضيات.جذر (square root), and print the distance from (0, 0) to (3, 4), and from (1, 1) to (2, 2) to three decimal places with رياضيات.نسق.

Show the solution
Solution
استورد رياضيات
داله مسافة(س1 كسر64, ص1 كسر64, س2 كسر64, ص2 كسر64) كسر64:
ارجع رياضيات.جذر((س2 - س1) * (س2 - س1) + (ص2 - ص1) * (ص2 - ص1))
اطبع(مسافة(0.0, 0.0, 3.0, 4.0))
اطبع(رياضيات.نسق(مسافة(1.0, 1.0, 2.0, 2.0), 3))
Output recorded from the compilermeem 11_حل.م · meem 0.17.3+434e13f
5.01.414

Modules · Standard library