SIMPOL Documentation

Comparison Between Language Primitives in SIMPOL and SBL

The following table contains a comparison between the language primitives in SBL and SIMPOL.

Table 20.1. Comparison of SBL key words to SIMPOL equivalents
SBLSIMPOLComments
ANDand, AND The AND operator in SBL although not described as such in the online documentation is actually a bit-field operator. The reason that this is not obvious is that in most cases it is used for Boolean comparisons together with the IF statement and that particular statement in SBL compares with false, which is the value zero. Anything that is not equal to zero is considered to be true. In SIMPOL there are two different operators, the and and the AND. The lowercase version is used for Boolean comparisons where the result will be one of the special values: .true or .false. The uppercase version is specifically used for testing whether certain bits in a value are on or not by using a mask. For a proper explanation of bitwise operators see the Appendix in the SIMPOL Language Reference manual.
DIM, GLOBAL, REDIM, ERASE, CLEARtypename variablename There has been some discussion about adding the dim and as key words to the language as aliases but the current assessment is that with the advent of so many languages that use the same approach as SIMPOL there is no real advantage to providing an alternative method of declaring variables. In SBL there is a number of ways to create a variable: using the DIM key word within a procedure or function creates a local variable, using it outside (assuming the program is not started with a SUB main() creates a global variable. Forms that have variables on them cause those variables to be created as global variables. Using the GLOBAL key word creates a global variable. Just using a variable name (this does not apply to object variables) within a procedure or function creates the variable locally if no variable exists with that name at the global level. If the program is not in a procedure or function and was started without a SUB main() then using a variable name creates a global variable. The ERASE command erases a single variable or multiple variables (both local and global)when using wild cards. The ERASE command works only if the variable is not used on a form (and never has been) if any form is open. The REDIM command is used to resize an array variable in SBL In SIMPOL there are no global variables, so all of that complexity disappears. All variables must be declared in SIMPOL before they can be used. If a variable is declared at one point in the function and then redeclared in another point, then it is destroyed and recreated at that point. Many SBL programmers use the DIM command only to create arrays. One of the common causes of difficult to detect side-effects in SBL programs is that of not dimensioning (declaring) variables in the appropriate locations. Although it allows faster programming it results in more expensive maintenance. Arrays in SIMPOL are quite different from those in most languages, since they do not need to be sized at the beginning and they are not an array of a specific type, they are themselves an object and can contain any arrangement of items desired and can also contain a mixture of types. This makes them quite flexible, but requires some thought at times to decide if they are the best approach to a problem. SIMPOL comes with a library of various pre-designed types that often provide a better solution to storing a collection of items, such as the objset and the list types. Just as the ERASE command is unnecessary, the same is true of the CLEAR.
FORNEXT [STEP]whileend while In addition to the WHILE loop construct SBL also provides a FOR block statement. In SIMPOL the whileend while block statement is the only looping construction. The reasoning behind this decision was that the FOR statement is essentially a special case of the WHILE and therefore unnecessary. There would be no speed advantage since the language is compiled.
FUNCTIONEND FUNCTIONfunctionend function A function in SBL is required to have a data type extension of either the dollar sign ($) or one of the numeric value symbols (%, %%, &%, #%, or !%). The return value of the function is assigned to a local variable that carries the same name as the function itself. In SIMPOL, the return value of the function is the value of the expression that immediately follows the end function statement. This value (or object) can be of any type and there is no standard syntactic way of telling the type of the return value of a function. The type of the return value can even change depending on certain things, such as the data typea that are passed to the function to begin with! Also, it is not required to make use of the return value in SIMPOL, so a function that has a return value can be called without assigning the return value.
IFTHEN|GOTOELSE IFTHENELSEEND IFifelse ifelseend if In SBL there are several kinds of IF statement. There is the IFGOTO single-line statement that has no equivalent in SIMPOL (GOTO is not supported in SIMPOL). There is also the normal single-line IFTHENELSE command that does not require an associated END IF statement. Finally there is the multiline block version that requires an END IF statement. In SIMPOL the only form that exists is the latter block form that requires the end if statement. This is part of the design philosophy of SIMPOL, in that every command and/or block statement has a single entrance and exit. Also, SBL is essentially a line-oriented language that is interpreted, whereas SIMPOL is a statement-based language that is compiled. The end-of-line character still ends a statement in SIMPOL and there is also a line continuation character so that long programming lines can be spread over multiple lines. Even if an if-statement is on a single line in SIMPOL it must be followed by an end-of-statement character (: or ;) and then the end if statement.
NOTnot The NOT operator in SBL although not described as such in the online documentation is actually a bit-field operator. The reason that this is not obvious is that in most cases it is used for Boolean comparisons together with the IF statement or in a WHILE loop as an exit condition. To work as a Boolean operator it needs to be applied to an expression and that particular statement in SBL compares with false, which is the value zero. Anything that is not equal to zero is considered to be true. In SIMPOL there are two different operators, the and and the AND. The lowercase version is used for Boolean comparisons where the result will be one of the special values: .true or .false. The uppercase version is specifically used for testing whether certain bits in a value are on or not by using a mask. For a proper explanation of bitwise operators see the Appendix in the SIMPOL Language Reference manual.
ORor, OR The OR operator in SBL although not described as such in the online documentation is actually a bit-field operator. The reason that this is not obvious is that in most cases it is used for Boolean comparisons together with the IF statement and that particular statement in SBL compares with false, which is the value zero. Anything that is not equal to zero is considered to be true. In SIMPOL there are two different operators, the or and the OR. The lowercase version is used for Boolean comparisons where the result will be one of the special values: .true or .false. The uppercase version is specifically used for setting certain bits in a value to the on or off by using a mask. For a proper explanation of bitwise operators see the Appendix in the SIMPOL Language Reference manual.
SELECT CASECASECASE ELSEEND CASE | SELECTifelse ifelseend if There is currently no SELECT CASE block statement in SIMPOL. Although the SBL block statement provides a certain ease of reading and expression in the code, it was decided that unless the implementation of a block statement of this nature actually provided more or different functionality to that of the if statement, it was not worth crowding the field of key words with yet another. There is discussion about adding a statement like this but with the added capability that is found in the C programming language of being able to fall through to the next case unless a break statement is encountered. This would add a useful capability that is not otherwise provided by the if statement.
SUBEND SUBfunctionend function In SIMPOL there is no difference between a function and a procedure (SUB) except that a function that is used like a procedure has no return value. The other basic difference is that there is no practical limit to the number of parameters that can be passed (in SBL this is limited to 15), and parameters can be passed by name or even left out. There is no CALL key word in SIMPOL, functions are called by using their name directly.
WHILEWENDwhileend while The SBL version of the WHILE loop always tests the condition at the beginning of the loop. It also allows the programmer to break out of the loop using the END WHILE command. In some cases programmers have used additional WEND statements inside the loop to cause the program to immediately return to the beginning of the loop, but this is technically incorrect and is not supported by the language. The SIMPOL version allows a condition at the beginning and the end of the loop, and either or both can be set. There is no command for breaking out of the loop from somewhere in the middle, in keeping with the design philosopy of SIMPOL. Some languages provide a slight variation of the WHILE loop known as: REPEATUNTIL or DoLoop While. This block statement allows the block to always execute once before the test is applied since the test is at the end of the block. In SIMPOL this is accomplished by using the while statement with an ending condition but no starting condition. In current SIMPOL code it is quite common to see both conditions used: the first for the main test and the last to test for errors. The final test is best read as: "end the while if the condition is true".