Illustrate "anonymous recursive functions" à la PowerShell

Wrote up a nice little macro in @racketlang to illustrate "anonymous recursive functions" à la PowerShell.
GitHub - shriram/anonymous-recursive-function: Anonymous recursive functions in Racket

https://discord.com/channels/571040468092321801/832076990923669554/1412961060129865768

Posted in discord Show & Tell by @shriramk

The mentioned rec macro is also in srfi/31, which I'd use in preference of dragging in the legacy mzlib libraries.

The SRFI-31 documentation mentions the named-lambda form that was in very early versions of Scheme (It was dropped in R3RS). I resurrected it for my soup library as another alternative:

(require soup-lib/control)
((named-lambda (fact n) (if (zero? n) 1 (* n (fact (sub1 n))))) 5) ; 120

A Clojure style loop/recur form would be easy to implement too (Assuming nobody's done it yet. Edit: Someone did it. And by someone I mean me. I'd forgotten about that.)

2 Likes