CLEAR Statement ---------------------------------------------------------------------------- Action Reinitializes all program variables, closes any open files, and optionally sets the stack size. Syntax CLEAR -,, stack&- Remarks The CLEAR statement performs the following actions. - Closes all files and releases the file buffers. - Clears all common variables. - Sets numeric variables and arrays to zero. - Sets all string variables to null. - Reinitializes the stack and, optionally, changes its size. The stack& parameter sets aside stack space for your program. BASIC takes the amount of stack space it requires, adds the number of bytes specified by stack&, and sets the stack size to the result. Note Two commas are used before stack& to keep BASIC compatible with BASICA. BASICA included an additional argument that set the size of the data segment. Because BASIC automatically manages the data segment, the first parameter is no longer required. If your program has deeply nested subroutines or procedures, or if you use recursive procedures, you may want to use a CLEAR statement to increase the stack size. You also may want to increase the stack size if your procedures have a large number of arguments. Clearing the stack destroys the return addresses placed on the stack during a GOSUB operation. This makes it impossible to execute a RETURN statement correctly, and BASIC generates a RETURN without GOSUB run-time error message. If you use a CLEAR statement in a SUB or FUNCTION declaration, BASIC generates the run-time error message Illegal function call. BASICA BASICA programs using CLEAR may require modification. In BASICA programs, any DEF FN functions or data types declared with DEF type statements are lost after a CLEAR statement. In compiled programs, this information is not lost because these declarations are fixed at compile time. See Also ERASE, FRE, SETMEM, STACK Function Example The following statement clears all program variables and sets aside 2,000 bytes on the stack for the program. CLEAR ,,2000