Welcome Guest. Please Login or Register. Apr 1st, 2018, 04:24am
ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018. We apologize Conforums does not have any export functions to migrate data. Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.
Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
Re: Subtle difference in scope rules
« Reply #1 on: Sep 2nd, 2014, 6:02pm »
But your sub comes across an exit sub and does not wait in the sub so the scope is back to the main program wait? So I would expect the lb4 result I would not expect LBB result.
But your sub comes across an exit sub and does not wait in the sub so the scope is back to the main program wait? So I would expect the lb4 result I would not expect LBB result.
There are two common applications of scope: 'lexical' (static) scope and 'dynamic' scope, as described in this Wikipedia article:
Lexical scoping is the most common in modern programming languages: the scope is determined at compile time according to where in the source code the identifier is referenced. It is clear that, using this definition, the way LBB works is correct.
What you seem to be describing is 'dynamic scope', which is used by a few languages, notably Lisp and Perl, although the situation I described is not typical of the way in which dynamic scoping is generally applied (one function calling another).
Realistically it would be impractical for LBB to work any other way, and in my opinion it is highly desirable for the destination of the 'trapclose' to be determined at compile time (i.e. be predictable) rather than at run-time (and be potentially unpredictable). It also accords with the principle of 'information hiding'.
But a well-written program ought not to depend on this behaviour anyway. As I said, simply omitting the label within the subroutine makes the program work just the same in LB4 and LBB.