Is there a fixed point combinator for creating tuples of mutually recursive functions? I.e. I'm looking for something like the Y-Combinator but which takes multiple "recursive"* functions, and will return a tuple of functions?
*: not really recursive of course, as they are written to take themselves (and siblings) as arguments, in the usual Y-Combinator way.
The creature you are looking for is Y* combinator.
Basing on this page by oleg-at-okmij.org I ported the Y* to Clojure:
The classic example of mutual recursive function is even/odd so here is the example:
You can easily blow the stack with this functions if you use big enough arguments, so here is trampolined version of it for example completeness which do not consume stack at all:
The Y* combinator is very useful for defining mutual recursive definitions of monadic parsers, of which I'll blog soon on lambder.com , stay tuned ;)
-- Lambder