Breaking circularity in fallback methods

What about this trick?

fg(x, y, undef=false) = if undef "stack","overflow" else f(x,y), g(x, y) end;

f(x, y, undef=true) = fg(x,y,undef)[1]
g(x, y, undef=true) = fg(x,y,undef)[2]

You could overwrite without undef argument:

f(x::Int, y) = 0
g(x::Int, y) = 0

fg(1,1) # -> (0, 0)
fg(1.,1)  # -> ("stack", "overflow")

1 Like