Coming from Python
You will find familiar things in Meem: blocks by indentation after :, لكل ... في (for … in), and lists and dictionaries in insertion order. The big differences: types are static and checked before the program runs, the program is compiled to an executable, errors are values rather than exceptions, and memory is manual.
What corresponds to what
Section titled “What corresponds to what”| In Python | In Meem |
|---|---|
if / elif / else |
اذا / غير ذلك اذا / غير ذلك |
for x in range(1, 11): |
لكل س في مدى(1, 11): |
while, break and continue |
طالما, توقف and تجاوز |
def f(x: int) -> int: |
داله ف(س عدد64) عدد64: (types are mandatory, and numbers have sizes) |
list and dict |
قائمة[نوع] (one type) and قاموس[مفتاح, قيمة] |
a class with fields |
a هيكل with fields, and functions take it as a parameter (no methods) |
import math then math.sqrt |
استورد رياضيات then رياضيات.جذر |
print(a, b) |
اطبع(ا, ب): no space between the values; write it yourself |
try / except |
!نوع, جرّب and والا |
None and Optional[int] |
لاشيء (nothing) in an optional type: عدد64؟, نص؟ (since 0.11.0), checked before use |
return a, b |
a tuple: داله ف() (ا عدد64, ب عدد64): and ا, ب = ف() (since 0.14.0) |
What is different
Section titled “What is different”A variable’s type is fixed by its first value:
س = 1س = "واحد"Exit code: 2
In the error catalog: E0408
/ between two integers is integer division, truncating toward zero (close to Python’s //, but different for negative numbers), and with a float it is fractional division. Meem does not mix an integer variable and a float without a conversion (كسر64(ن) / 2):
الطول = 7العرض = 3اطبع("المساحة: ", الطول * العرض)اطبع("المحيط: ", 2 * (الطول + العرض))اطبع("7 / 2 = ", 7 / 2, " و7 / 2.0 = ", 7 / 2.0)No exceptions: a function that can fail says so in its type, and handling it is mandatory at compile time:
اخطاء: قسمة_على_صفر
داله اقسم(ا عدد64, ب عدد64) !عدد64: اذا ب == 0: ارجع خطأ.قسمة_على_صفر ارجع ا / ب
اطبع(اقسم(10, 2) والا -1)اطبع(اقسم(10, 0) والا -1)ن = اقسم(7, 0) والا خ: اطبع("فشل: ", خ) 0اطبع(ن)Memory is manual: there is no garbage collector. In a short program that does you no harm, because everything returns on exit. In a long loop, you free what you build with خاتمه حرر(...). Start with memory for beginners: three rules.
Performance compared with Python (measurements on 0.9.1)
Section titled “Performance compared with Python (measurements on 0.9.1)”In the direction report: algorithms are much faster (on a par with C), and text processing is on a par with Python in time (0.70 s against 0.74), but with about 7 times the memory, because the program read the whole file (there was no line-by-line reading before 0.14.0). Details in what Meem can and cannot do.