Skip to content

writing-motoko: general Motoko items dropped vs prior coverage (persistence flags, M0220/M0141/M0064/M0145, Text.join/variant-paren pitfalls, reserved-keyword list, equality breakdown) #3

Description

@marc0olo

Thanks again for the quick fixes on the earlier issues!

Context: we're migrating our Internet Computer skills site (dfinity/icskills) to sync writing-motoko, migrating-motoko-actors, and troubleshooting-motoko-migrations from here. As part of that we compared the content we're replacing (our older Motoko skill) against the new writing-motoko corpus (SKILL.md + api-reference.md + examples.md + references/*).

writing-motoko is richer than our old skill in most areas (mops toolchain, Nat-arithmetic safety, numeric-conversion hygiene, text search/case folding, array sorting, a much larger error table, the API reference). But a handful of general (non-Caffeine) Motoko items our old skill covered aren't in the new corpus anywhere. We'd like to sync the core generically, so rather than carry these as local patches we'd prefer they live upstream — could you consider adding them? (If you'd rather they stay out of scope, that's fine too — we'll drop them on our side. Just want an explicit decision so we're not silently diverging.)

1. How enhanced orthogonal persistence is actually enabled

The body says state persists "without the stable keyword" but never explains how EOP is turned on. On Caffeine the mops toolchain sets this automatically, so it's invisible — but a general reader compiling with moc/mops manually hits M0220 with no guidance. Our old skill had:

--default-persistent-actors          all actors are `persistent`, no `stable` keyword needed

--enhanced-orthogonal-persistence is on by default. Without --default-persistent-actors, plain actor { } errors with M0220 — write persistent actor { } instead (the persistent keyword is transitional; actors become persistent-by-default in a future major moc release).

Plus the auto-fixable style-enforcement warnings that back the skill's own conventions: -W M0236 (non-dot-notation calls), -W M0237 (redundant explicit implicit args), -W M0223 (redundant type instantiation).

2. Error-table rows dropped

Present in our old table, not in the new one:

Error Meaning Fix
M0220 actor should be declared persistent --default-persistent-actors or persistent actor
M0141 type/let declared before the actor body move them into the body / into types.mo
M0218 redundant stable keyword remove stable (plain var is auto-stable)
M0064 misplaced '!' wrap in do ? { ... }
M0145 pattern does not cover value add missing cases or case _

(We had previously flagged M0064 and M0145 upstream at caffeinelabs/motoko — issues #6157 and #6156 — but since that repo is being retired, re-surfacing here.)

3. Pitfalls dropped

  • Text.join parameter order — iterator first, separator second: Text.join(["a","b"].values(), ", "). Easy to invert.
  • type/let before the actor body (M0141) — only imports may precede the actor; move types into types.mo.
  • Parenthesize variant tag arguments#tag(x), never #tag x (#tag 1 + 2 parses as #tag(1) + 2).
  • Never annotate lambda argument types — the compiler infers them; annotating is redundant and often wrong.

4. Reference material dropped

  • Full Reserved Keywords list. The new corpus names query/label as reserved (Critical Requirements + one error row) but has no enumerated list. Our old skill listed all of them (actor and assert async await break case … with, plus the async*/await*/await? note) so an agent can check an identifier before using it.
  • Equality & Comparison breakdown. Which mo:core modules expose a self-callable .equal (Text, Principal, Bool, Char, Blob) vs the x, y form (Nat, Int, Float, sized ints), and that == is compiler-generated structural equality while equal/compare are primarily implicit arguments for Map/Set/contains.
  • do ? { ... } option-chaining construct (the counterpart to the M0064 misplaced-! fix above).

None of these are Caffeine-specific — they're general Motoko/moc correctness items. Happy to open a PR adding them to writing-motoko if that's easier than doing it yourselves. And if any are intentionally omitted, just let us know and we'll drop them on our side.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions