3.9 The layout of the Variable Area

There are special words that allow you to get information about the layout of the Variable Area. They are called 'VARS', 'APP', 'FIRST' and 'LAST'.

'VARS' is the address of the very first variable. Before that is the Stack Area. 'APP' is the address of the first application variable. All variables before that are 4tHs own built-in variables. 'FIRST' is the address of the first user-variable, a variable you defined yourself in your 4tH program. 'LAST' is the address of the last accessable variable, so

     last ?

will *NEVER* fail. The first question that will pop in your mind is, what can I do with them. Well, you can use it to see how many variables there are of a certain kind, so you can prevent runtime errors:

     ." number of 4tH variables: "              app vars - . cr
     ." number of application variables: "first app - . cr
     ." number of user variables: "          last first - 1+ . cr

These tests are possible too:

     app vars - 0= if ." No 4tH variables" cr then
     first app - 0= if ." No application variables" cr then
     last first - 1+ 0= if ." No user variables" cr then

This is a general test to see whether the address of any variable is within range:

     dup 0<
     dup last >
     or
     if ." Out of range" cr then

You can use this check on numeric arrays too, of course.