So if I've got this right, the general gist of the function is that when the turtle encounters a vein of some sort, you want to use this function to recursively dig the whole thing out, and when the recursion is finished, the turtle should be located where it was when it started?
Lava lakes will kill that idea. They can get way too large for it. Your limit will be about a six-block-cubed area.
My general advice for recursion is this: There aren't that many applications that "require" it. No matter what the task, it probably isn't needed.
I guess if I were to try to take on this sort of task, I'd adapt
this script I made for
this "competition" (though unfortunately Konlab decided to butcher my code before running it, I can assure you it does work ;)/> ).
Ironically, it uses recursion, but not for the same task. The basic idea is that the turtle can explore an area, and keeps going until it either reaches a certain point or decides it's boxed it. If it reaches a dead end, it refers to a look-up table and paths back to the last location it knew
wasn't a dead end.
The recursion (which likely isn't needed at all, I just felt like using it! :P/> ) comes in just for navigating between these pre-explored points (and even then it doesn't check all possible paths - it only needs to inspect well under 1% of them to find the best). Finding new points is handled by a "while" loop instead. I'm not sure how large an area it can handle, but rather I can only really sum it up as "huge".
So, yeah, I'd rig that to treat ores/lava/whatever as "open spaces" it's allowed to explore through, and everything else as impassable terrain. Once it decides it's boxed in I'd tell it to go back to its starting position.
I'm sure you'll want to use all of your own code, but looking at my pathfinder may at least give you some ideas.