hn.today

Show HN: Combinators in Array Languages

blog.softwarewrighter.com3 points0 comments
Screenshot of Show HN: Combinators in Array Languages

Shows how to get anonymous recursion in a strict, array-oriented language by revisiting Smullyan’s Sage (the Y combinator) and why the classical form fails under eager evaluation. The Sage as λf.(λx.f (x x))(λx.f (x x)) satisfies Y f = f (Y f) but diverges in a strict evaluator because self-application is forced immediately. sw-MLPL models combinators as ordinary named defs (the bird vocabulary: Mockingbird, Bluebird, Lark, etc.) and includes the classical Sage but deliberately never forces it; that exposes the core problem without changing the language semantics.

The practical solution is the applicative Sage, a Z-style combinator that delays self-application by using a named partial (a unary function value) so the evaluator won’t immediately evaluate the knot. Concretely, step = call(:u:z_step, builder); call(step, step) ties the knot safely and yields working examples (factorial(6) = 720, fibonacci(8) computed) without adding laziness. The write-up argues against making sw-MLPL lazy - strictness gives predictable costs and matches APL lineage design where named defs already handle recursion or fixed points are provided by primitives like ∇, 𝕊, .z.s or operators such as J’s power-limit. A three-step recipe is given: write a body that receives its recursion, tie the knot with applicative_sage, and call it; runnable code lives in demo-combinators/src/fixed_points.mlpl and lesson 17.

Read on blog.softwarewrighter.com0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.