Coming from Zig
Meem is closer to Zig than to any teaching language: an allocator is a value that is passed around, خاتمه corresponds to defer, and !نوع corresponds to !T. Zig was not installed on the analysis machine, so what is said here about Zig comes from its documentation and is not tried.
What corresponds to what
Section titled “What corresponds to what”| In Zig | In Meem |
|---|---|
passing a std.mem.Allocator |
the allocator as the last argument, which may be left out, and then الافتراضي is passed |
ArenaAllocator |
ساحة(الاصل) and اعد |
FixedBufferAllocator |
مخزن_ثابت |
GeneralPurposeAllocator in debugging |
the detector, on by default in meem برنامج.م and with --debug in meem build; --debug-mem adds the leak report |
defer / errdefer |
خاتمه / خاتمه_عند_خطأ |
!T, try, catch |
!نوع, جرّب, والا |
error{...} |
an اخطاء: (errors) block, and an optional error set in the signature: !{غير_موجود, ممنوع} نص (since 0.11.0) |
?T |
ن؟ (since 0.11.0), with والا (else) for a fallback |
fn max(comptime T: type, ...) |
داله اكبر[ن](ا ن, ب ن) ن:, inferred from the arguments (since 0.15.0) |
| Debug / ReleaseFast | a direct run with the detector / meem build or --release without it. Bounds and overflow are checked in both modes, and بلا_فحص inside خطر switches that off locally |
داله عالج(ن عدد64) نص: اطبع("فتح المورد ", ن) خاتمه اطبع("إغلاق المورد ", ن) خاتمه اطبع("تنظيف أول") اذا ن < 0: ارجع "سالب" اطبع("عمل على ", ن) ارجع "تم"
اطبع(عالج(5))اطبع("---")اطبع(عالج(-1))اخطاء: ملف_تالف
داله حمّل(صالح منطقي) !عدد64: اطبع("فتح") خاتمه اطبع("إغلاق") خاتمه_عند_خطأ اطبع("تراجع عن نصف العمل") اذا !صالح: ارجع خطأ.ملف_تالف ارجع 42
اطبع(حمّل(صواب) والا -1)اطبع("---")اطبع(حمّل(خطاء) والا -1)Where Meem departs from Zig’s model (0.17.1)
Section titled “Where Meem departs from Zig’s model (0.17.1)”- «No hidden allocation» is the rule since 0.10.0, with one exception: growing with
ن += ذيلleaves the old buffer behind (a bounded leak of about twice the final length). In 0.9.1, operations on a «view» allocated copies that were never given back. - Slices and strings: a string is
{pointer, length, owner}, and a view is a string on the bytes of another string, living as long as it does. - No
comptime: generics use type parameters copied for each combination, and a constraint is a trait (سمةandيحقق, since 0.17.0), not code run at compile time. - No user-written allocators, and no
resizeor alignment. - The detector works at run time, not compile time, it does not see C memory, and
حررdoes not follow what is inside a container (no deepdeinit). - No full error trace: «نشأ في» (originated in) with the line of the first
ارجعthat returned it, and a «ثم» (then) line for eachجرّبit passed through in a direct run (since 0.11.0); Zig has a full error return trace in debug builds.
See also
Section titled “See also”Memory in Meem · Dealing with errors · Meem compared with C and Zig