I love functional programming in Octave, but it's rather unwieldy in practice. I'm wondering about the shortest way to define an anonymous recursive function.

I have some ideas, but I'm wondering if there is a way to combine these ideas to make them even shorter (or equally short but more versatile). For the sake of this question, let's recursively count down to zero (just to keep the payload as simple as possible).

If my reasoning is correct, none of the variable names I used in the following examples should overlap. The desired function is q(n), which should always return zero. i is used as a counter variable, f is the recursive function which I have called g in the local scope of f.

44 bytes, "inline definition of f"


44 bytes, "argument list definition of f"


44 bytes, "separate definition of f"


41 bytes, "desired function as a return value"


The current 'winner' is inspired by this answer by flawr. However, given the large range of different ways to do this, perhaps someone can think of an even shorter combination of methods.

The goal is of course to get it below 39 bytes for a "full" function, Try it online!


1 Answer 1


Octave, 39 bytes


Try it online!

  • \$\begingroup\$ Wow I did not expect that you could define a function in it's own argument list. Well done! \$\endgroup\$
    – Sanchises
    Commented May 9, 2018 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.