🏠 back to Observable

[feature request] Allow circular function definitions

Some circular function definitions are valid as illustrated in https://observablehq.com/@vramakin/valid-cycles but Observable always throws an error when it sees a circular definition. This prevents valid mutually recursive functions from being defined. So, can the circular definition check be disabled for function definitions ? I understand this is a rarely used feature; it will be nice to have it though.

it will be nice to have it though

Do you have a concrete/practical case where you have wanted this?

I was trying to use mutual recursion for a backtracking algorithm. After refactoring I realise the code reads better without mutual recursion. I’ll post here if I find more concrete cases.

FYI, the backtracking algorithm was something like this -

function solve(inp, op):
    if(deadEnd) return stepBack(inp,op)
    else if(goodEnd)
        return stepBack(inp,op)
    else return solve(next(ip),op)
function stepBack(inp, op):
    if(backToStart) return op
    else return solve(prev(inp),prev(op))