Concerning "GOTO to another GOSUB", it wouldn't be a proper vision of the problem. You may not goto to another sub freely while in recursion. For you to have the right to goto, the both ends of the jump must be at the same recursion depth level or the stack will get disbalanced sooner or later, which will end up in an inevitable crash.
I'm confused. Are you speaking of SBLisp's stack or Script BASIC's stack?
I'm theorizing out loud. You can't
GOTO to a label that expects a
GOSUB because you'll eventually hit a
RETURN that'll cause a runtime error. Similarly you can't
GOSUB into a
GOTO label unless it ends up in an
END command.
RETURN is a command that exits from the current
GOSUB unwinding the process stack of the engine (SB or FBSL or O2, whatever) by one call stack frame, that is by one recursion depth level if recursion is taking place or by one nested call level if the call has been made to another
GOSUB label. It then resumes execution from the line that follows the
GOSUB line.
QB's
RETURN Label implements an interesting functionality that combines two steps in one. First it returns as an ordinary
RETURN described above. However it doesn't then resume execution from the line that follows but instead
GOTO-es all by itself to the label denoted by
Label. Thus you can override the resumption line without giving a damn where it actually is and instead jump to another
GOTO label anywhere in the top-level code -- and
HandleError is a top-level
GOTO label in the QB code of Lisp-in-Basic. And this phenomenon repeats on and on until
BSD reaches zero, which means all levels of nesting/recursion have been unwound and the code pointer may safely
GOTO to the main loop labeled
LispReadEvalPrintLoop.
Does that make sense now?
Until you realize how the QB code really works, you won't be able to reimplement its functionality in full with somewhat different means at hand in SB, FBSL, and O2. You should understand that I'm vocalizing all these things only to keep you informed of what's going on in XBLisp code and why. If I were alone on this project, I would've been doing all my work in complete silence.