Block-form methods: write a callback’s names and body at the call site.
The operative sees the binding list, which is what makes the optional
index possible: the language has no arity introspection.
BlockBlock-form methods: give a higher-order method a (names …) body … call shape.
(Block %all-syms? xs)(Block %len>=? xs n)(Block %name-count xs)(Block %but-last-n xs n)(Block %last-n xs n)(Block %eval-each xs e)(Block %block-call? args pos n)(Block %nth xs i)(Block %take-n xs n)(Block %drop-n xs n)(Block %append a b)(Block %shape-error what n)(Block %shape-element blk n)(Block %shape-pair blk n)(Block %shape-fold blk n)(Block %shape-binary blk n)(Block %shape-thunk blk n)(Block %adapt shape blk n)(Block %block-fn names body e)(Block %block-op m shape trailing pos)(Block %shape-names shape)(Block %shape-alt shape)(Block %meta-param-names meta)(Block %entry-param-names triples)(Block %join-args names pos seat i)(Block %block-head class sel static? names pos seat)(Block %last-cell xs)(Block %nth-cell xs i)(Block %pending-entry key)(Block %notes-have? strs text)(Block %meta-has-note? meta text)(Block %doc-note! class sel shape static? pos)(Block %imethod-of class sel)(Block method! class sel . opts)Give a higher-order method a block form: (subject sel (names …) body …).
Shapes: element (default) – (x) or (index x); pair – (p) or (key value);
fold – (acc x) or (acc index x); binary – (a b), no index;
thunk – (), a nullary callback such as a lazy default.
Trailing defaults to 1 for a static method (the subject) and 0 for an
instance method (the receiver is self); fold needs 2 (init, subject).
Position defaults to 0; (List times n f) wraps at 1, the count
ahead of it evaluating in the caller’s env.
The applicative form keeps working unchanged, and (help Class/sel)
still answers from the doc registry.
Do NOT (method-of Class sel) a block-enabled selector: the stored
method is now an operative and a direct call would not evaluate.
Parameters:
CLASS — Class owning the methodSYMBOL — Selector to give a block formLIST — Optional: shape symbol, trailing-argument count, callback positionReturns: ANY — The installed operative
Examples:
(do (Block method! List 'map) (List map (x) (* x 2) (list 1 2))) => (2 4)