GOTO Label goes to a specified label.
What if we want something like a function that can return?
We could use a stack, and something like CALL and RETURN commands, but I have two propositions for ways that are more aligned with the simplicity style of the language.
Jump to Variable
A simple way could be letting the user jump to a label stored in a variable. This is less readable but really flexible (and could lead to some funny looking programs which is a plus).
% Return to the label resolved in expression.
RETURN (expression)
Or
% Return to the label resolved in expression.
GOTO LABEL (expression)
END (Label)
This effectively implements CALL and RETURN aligns well with the way the rest of the language looks and feels. We have to keep a call stack of labels that have matching "END label" commands however.
If this is added potentially GOTO between sections should be disallowed. (Labels inside subroutines cannot be jumped to outside the subroutine)
a = 5
GOTO Process
END
# subroutine Process
Process:
PRINT a
END Process
GOTO Label
goes to a specified label. What if we want something like a function that can return?We could use a stack, and something like CALL and RETURN commands, but I have two propositions for ways that are more aligned with the simplicity style of the language.
Jump to Variable
A simple way could be letting the user jump to a label stored in a variable. This is less readable but really flexible (and could lead to some funny looking programs which is a plus).
Or
END (Label)
This effectively implements CALL and RETURN aligns well with the way the rest of the language looks and feels. We have to keep a call stack of labels that have matching "END label" commands however. If this is added potentially GOTO between sections should be disallowed. (Labels inside subroutines cannot be jumped to outside the subroutine)