Full BASIC is a programming language for those who are not familiar with common knowledge about computer industry.
BASIC is a programming language developed by John.G.Kemeny and Thomas E. Kurtz at Dartmouth College around 1964.
The languages that many people think of as BASIC, such as Microsoft BASIC or so, look similar to the orignal BASIC, but there are some significant differences.
These languages inherit syntax adapted for microcomputers. Early microcomputers were unable to use enough memory, so energy was poured into cramming BASIC processing systems into limited ROM capacity.
One of the techniques employed for this purpose is implementing as an interpreter, but it is not the only technique employed to make it small.
These had made it possible for many people to obtain cheap computers in which BASIC can be used, but it has undermined the essence of BASIC, which was born as a language for beginners.
Work began in 1974 to standardize BASIC, and four years later, in 1978, it was standardized in the United States and Europe as Minimal BASIC.
In 1982, the International Organization for Standardization (ISO) draft was prepared, and in 1984 the Minimal BASIC international standard was established.
In Japan, Minimal BASIC was standardized in 1982.
Following the standardization of Minimal BASIC, work began on standardizing the full version of BASIC (Full BASIC), but this work appears to have been quite difficult.
The original draft was created in 1982, and the standard was established in Europe in 1986 and the United States in 1987. The International Organization for Standardization (ISO) established the Full BASIC ISO standard in 1991, which encompasses European and American standards. In Japan, the JIS for Full BASIC was established in 1993 as ISO-compliant.
In 1989, additional provisions for modular and individual character input were standardized in the United States. These are included as a reference in JIS.
BASIC for microcomputers has been widely used as a language for system development. In Visual BASIC, you can't do anything without creating a form and creating a button on the form to start execution and a window to display the results. Visual BASIC is a language for writing programs for others to use, not for solving writer's own problems.
However, BASIC is originally problem-solving oriented. A program is written to solve the problem of the person creating the program themselves.
Full BASIC is designed to be used by non-computer experts to solve problems themselves. There are some innovations that are sure to be useful even to people who don't know the common sense of the computer world.
A simple characteristic of Full BASIC is its Rigorous syntax.
Full BASIC prohibits potential ambiguities to prevent the machine from misrepresenting the program's author's intentions syntactically.
In interpreted BASICs, syntactical errors are detected at runtime. However, in Full BASIC, syntactical errors are detected before the program starts running. In other words, at Full BASIC, finding syntactical errors is the job of machines, not humans.
The 18 reserved words in Full BASIC are:
NOT,ELSE,PRINT,REM,PI,RND,MAXNUM,TIME,DATE,EXTYPE,EXLINE,ZER,CON,IDN,TRANSFORM, DATE$, TIME$, NUL$
In Microsoft BASIC, painstakingly created programs often ran into reserved words and didn't work, but in Full BASIC, there are only 18 reserved words in total, so you won't have any trouble writing a program that avoids reserved words.
Full BASIC has a standard called subset core, in which case the number of reserved words increases. However, even in that case, processing systems are not allowed to increase the reserved words.
Microsoft BASIC's key-words include many abbreviations that combine multiple words and simplify them, such as CDBL, CINT, PSET, or CLS. In addition, there are multi-functional statements such as LINE statements and CIRCLE statements, where multiple parameters are arranged side by side.
Even in standard BASIC, early established syntax often use three-letter abbreviations, mainly for numeric function names such as SIN, COS, TAN, LOG, EXP, ATN, RND, and MOD, but syntax added in the relatively new era is composed without using abbreviations to write even long spellings, such as below
OPTION ARITHMETIC DECIMAL
OPTION ANGLE DEGREES
SET POINT COLOR
SET LINE STYLE
Also, there is no syntax that allows you to specify many parameters in one command. This increases the number of letters in a program and typing effort, but makes it easier for beginners to recall the meaning.
In Full BASIC, numbers are all floating point decimal fractions and there are no types of number such as double precision, single precision or integer type.
There are no errors that occur when approximating decimal fractions with binary fractions, so adding 0.1 10 times will result in exactly 1. For example, the following program runs 11 iterations, with the final result being exactly 0:
10 FOR x=-1 TO 0 STEP 0.1 20 PRINT x 30 NEXT x 40 END
Full BASIC has regulations regarding the accuracy of the results of performing numerical operations. This provision applies not only to arithmetic operations, but also to embedded functions such as exponentiation and SQR functions. Thanks to its provisions, you no longer have to worry about unexpected errors in exponentiation or SQR functions.
The following program finds all Pythagorean numbers less than or equal to 100, and is a correct program in Full BASIC. However, substandard BASIC cannot guarantee correct results. In fact, some old BASICs give incorrect results.
10 FOR x=1 TO 100 20 FOR y=x TO 100 30 LET z=SQR(x^2+y^2) 40 IF INT(z)=z THEN PRINT x,y,z 50 NEXT y 60 NEXT x 70 END
The four operations, addition, subtraction, multiplication, and division, and exponentiation are binary operations, but there is an exception.
When you write a negative sign at the beginning of a numeric expression, such as "-2*a+3", this negative sign is not a binary operation.
In Full BASIC, the positive and negative signs at the beginning of a numeric expression are also guaranteed to be treated equally to positive and negative signs of binary operations. However, from the perspective of creating compilers and interpreters, these exceptions are a bit of a problem.
Many languages other than standard BASIC eliminate this clunkiness by adopting syntax that treat negative signs that reverse sign as a prioritized unary operation. Microsoft's BASIC also uses this syntax.
Numerical expressions written in standard BASIC syntax can be correctly handled by Microsoft syntax. Judging by this fact alone, you may think that Microsoft's approach is better, but it is not.
Except for those who are thinking of making their own interpreters or compilers, it may seems to be normal that they do not think deeply about the syntax of numerical expressions. A wide range of syntax tolerance means that there is a greater possibility of discrepancies in the interpretation of meaning between machines and humans.
In BASIC, when you write operations of the same rank in a row, they are executed in order from the left. For example, 2^3^4 means (2^3)^4, so it becomes 4096. This is the same for Microsoft's BASIC.
In Microsoft BASIC, an unary operation has a promise that it takes precedence over exponentiation at the right of ^. Therefore, 2^(-3) can be written as 2^-3. However, 2^-3^2 and 2^(-3)^2 do not mean the same thing.
In Full BASIC, Numerical comparisons and logical operations AND, OR, and NOT are treated as belonging to a separate category from numerical operations.
However, logical operations are part of numerical operations in Microsoft BASIC.
A numerical comparison is a binomial operation of -1 when true and 0 when false.
Since the priority of numerical comparisons is set lower than addition and subtraction, for example, 1+2<4 means (1+2)<4, and numerical comparisons written in standard BASIC syntax can be handled correctly by Microsoft BASIC.
In Microsoft BASIC, numerical comparisons and logical operations are part of numerical operations, so they can be mixed into numerical expressions. For example, if you run,
10 PRINT 2+(1<3)
the answer will be 1. Similarly,
10 PRINT 2<1<3
is also can run, and the answer is -1 because 2<1<3 = (2<1)<3 = 0<3 = -1 in Microsoft's interpretation.
However, some people may say that 2<1<3 is false, so it should be 0. It is dangerous for such people to use Microsoft BASIC.
In Microsoft syntax, numerical expressions are written where logical expressions are supposed to be written, such as IF statements . And if the number is not 0, the condition is judged to be true. So, when you run the following in Microsoft BASIC
10 IF 2<1<3 THEN PRINT "Y" ELSE PRINT "N"
you shall get the result "Y". On the other hand, in Full BASIC, this statement is syntaxically incorrect and cannot be executed.
Microsoft BASIC distinguishes the type of numeric with a symbol such as !, % or # following numeric constants or variables . But Full BASIC has only one type of number.
Full BASIC uses the symbol "!" to write a tail comment. The right hand side of "!" is a comment. Therefore the following program shall be interpreted as different meaning. For example, In Full BASIC
10 PRINT 10!+15!
means PRINT 10 .
Full BASIC does not have the mod operators found in Microsoft BASIC. Instead, a mod function is provided. Also, since Full BASIC does not have an integer type, there is no \ operator that means integer division.
Full BASIC MOD function is defined as follows
MOD(x,y)=x-y*INT(x/y)
The domain is the whole real number. For example, MOD(9, 2.5) is 1.5.
There are notable differences between Microsoft BASIC mod operation and Full BASIC mod function.
Full BASIC's MOD function is the same as the definition of modulo in number theory, and the result has the same sign as the divisor, regardless of the sign of the dividend. On the other hand, in Micorsoft BASIC's mod operation, the sign of the result is the same as the sign of the dividend.
In most case, the divisor is a constant, so a mod function that matches the definition in number theory is often more convenient, but if a program written with Microsoft BASIC mod operations as its premise were rewritten as a mod function, it would not work properly.
Note that if you want a result similar to the Microsoft BASIC mod operation in Full BASIC, use the REMAINDER function. The REMAINDER function is deefined
REMAINDER(x,y)=x-y*IP(x/y)
where IP is defined as IP(x)=SGN(x)*INT(ABS(x)). IP(x/y) is equivalent to x\y in Microsoft BASIC.
In BASIC, the assignment statement is written in the form
LET variable = numeric expression
LET can be omitted in Microsoft BASIC. You may think that if something doesn't need to be written, it's easier not to write it, but the language that uses the equals sign to mean the calculation is not suitable for beginners. ( Decimal BASIC automatically compensates for LET when translating if you omit it, so if you don't want to bother typing LET, you don't have to.)
Consider the following
100 IF A<>0 THEN IF A=1 THEN GOTO 200 ELSE GOTO 300
In Microsoft's syntax, It is interpreted as follows, so when A=0, nothing happens.
IF A<>0 THEN IF A=1 THEN GOTO 200 ELSE GOTO 300
But,with
IF A<>0 THEN GOTO 200 ELSE GOTO 300
replacing GOTO 200 with IF A=1 THEN GOTO 200 make the same statement, so someone might write it intending
IF A<>0 THEN IF A=1 THEN GOTO 200 ELSE GOTO 300
Full BASIC prohibits the use of an IF statement in an IF statement to prevent the above problem.
In Full BASIC, you have no choice but to write as follows, but in this way of writing, the intention is clearly expressed.
IF A<>0 THEN IF A=1 THEN 200 ELSE 300 END IF
or
IF A<>0 THEN IF A=1 THEN 200 ELSE GOTO 300 END IF
Multi-statement is a syntax specific to Microsoft BASIC, which is not in standard BASIC. When dealing with beginners, they are often taught that it is okay to write two statements connected by a colon, but in reality, this may not be the case.
If we combine two statements
10 IF A=1 THEN GOTO 100
20 IF A=2 THEN GOTO 200
to get
10 IF A=1 THEN GOTO 100 : IF A=2 THEN GOTO 200
then it changes the meaning.
Unlike interpreted languages, Full BASIC has a type of statement that is processed at translation and cannot be controlled at runtime.
In interpreted BASIC such as N88-BASIC, DIM and DEF statements are processed at runtime, while in Full BASIC, DIM and DEF statements are processed at translation. Therefore, you cannot change the array or define functions in the execution .
Note that in Full BASIC, it is not necessary to start with FN for the name of the function to be defined in the DEF statement. Natural expressions like f(x) are possible.
While older types of Microsoft BASIC use ON ERROR GOTO statements for runtime error handling, Full BASIC provides a structured exception handling syntax. You can nest error handling, and you can also communicate and entrust processing to the caller for exceptions that occur during the execution of procedures such as subprograms and functions.
In Full BASIC, errors that occur at runtime are called exceptions. Full BASIC uses the structure WHEN EXCEPTION IN ~ USE ~ END WHEN. When an exception occurs between the WHEN and USE lines, it branches to the next line in the USE line.
Let's try adding exception handling to the following program:
10 DEF f(x)=1/x 20 FOR x=-10 TO 10 30 PRINT x,f(x) 40 NEXT x 50 END
Full BASIC has the characteristic of communicating exceptions in procedures. Exceptions that occur during a procedure are communicated to the caller if they are not handled during the procedure. For example, the next program actually throws an exception on 100 lines, but it is propagated to the caller's 130 lines and behaves as if the exception occurred on 130 lines.
100 DEF f(x)=1/x 110 FOR x=-10 TO 10 120 WHEN EXCEPTION IN 130 PRINT x,f(x) 140 USE 150 PRINT x,"error" 160 END WHEN 170 NEXT x 180 END
You can also do something like this:
100 DEF f(x)=1/x 110 WHEN EXCEPTION IN 120 FOR x=-10 TO 10 130 PRINT x,f(x) 140 NEXT x 150 USE 160 PRINT x,"error" 170 CONTINUE 180 END WHEN 190 END
CONTINUE is an instruction that instructs you to resume execution from the next line of the exception line, which is the equivalent of RESUME NEXT in Microsoft BASIC. The Full BASIC instruction equivalent to RESUME 0 in Microsoft BASIC is RETRY.
Memo: A new version of Visual BASIC, VB.NET, implements structured exception handling. The VB.NET's Try ~ Catch ~ End Try is equivalent to the Full BASIC WHEN EXCEPTION IN ~ USE ~ END WHEN. However, VB.NET does not seem to have the equivalent of Full BASIC CONTINUE or RETRY.
The meaning of the END staement is different between Microsoft BASIC and Full BASIC. In Microsoft BASIC, the END statement means to terminate the execution of the program, while the END statement in Full BASIC is used to indicate the end of the main program. In Microsoft BASIC, you can write any number of END statements anywhere, or you can write no END statements at all, but in Full BASIC, only one END statement is always written.
The Full BASIC statement which is the equivalent of the END statement in Microsoft BASIC is STOP.
Note: The Full BASIC equivalent of Microsoft BASIC's STOP is DEBUG ON and BREAK.
In Microsoft BASIC, DATA statements are wide over the entire program, but in Full BASIC, the scope of DATA statements is a program unit. Therefore, in a program that only has a main program, DATA statements must be written before the END line.
Full BASIC does not provide a label syntax to represent the branch destination of a GOTO statement. Full BASIC is structured to include error handling, so GOTO statements are rarely needed. However, if you really want to use a GOTO statement, use a line number. The fact that Full BASIC provide no labels should be understood as an intention to curb the abuse of GOTO statements.
GOSUB ~ RETURN subroutines should not be used in Full BASIC, a structured programming language, but they are left in the standard for compatibility. The caveat when using GOSUB statements is that it is not allowed to branch beyond the END line in GOSUB statements. Therefore, the subroutine itself must be written before the END line. In that situation, the command written before the subroutine is STOP.
In minimal BASIC, the lower limit of array subscript was 0, but in Full BASIC, the lower limit of array subscript has been changed to 1. Since the OPTION BASE statement is valid, if you write OPTION BASE 0, you can set the lower limit of the subscript to 0 as before.
In minimal BASIC, you could use an array without declaring it, but in Full BASIC, you cannot use it without declaring an array. This is because Full BASIC has added the function of user-defined functions, so without a declaration, it is impossible to determine whether it is a function or an array.
In Microsoft BASIC, you can use a simple variable and an array with the same name at the same time, but in Full BASIC, you cannot use a single name for both a simple variable and an array.
In Full BASIC, you cannot use DIM statements to turn simple variables into arrays or change the dimensions of arrays. Full BASIC treats array dimensions as grammatical attributes and inspect the program during translation. Therefore, it is impossible to cause errors in array dimensions at runtime.
Full BASIC is a language that allows you to write inputs and outputs in a concise way. MAT statements are provided for array output and matrix operations. MAT is the first three letters of "matrix".
When using a MAT READ statement, the data equal to the size of the array is read from the DATA statement.
10 DIM A(4) 20 MAT READ A 30 DATA 12,43,45,21
For two-dimensional or three-dimensional arrays, it reads in the order in which the following subscript changes first. For example,
if you have an array A declared by DIM A(2,3),
MAT READ A
will read A(1,1), A(1,2), A(1,3), A(2,1), A(2,2), A(2,2), A(2,3).
Therefore, if you want to treat array A as a matrix with two rows and three columns, you can set the default values in the following program.
10 DIM A(2,3) 20 MAT READ A 30 DATA 1,2,3 40 DATA 3,4,5
MAT INPUT statements can be used to write concisely input from the keyboard. When executing a MAT INPUT statement, all elements of the array must be separated by commas. While you don't put a comma at the end of a line in a DATA statement, you do need a trailing comma at the end of intermediate lines if you're using a similar MAT INPUT statement and want to enter a newline during input.
MAT PRINT statements can be used to output all elements of an array. In addtion, MAT PRINT USING statements are available.
In Full BASIC, the upper limit of subscripts to be declared in DIM is written as a constant. Therefore, it is not possible to change the size of the array in a DIM statement. As an alternative, there is a feature to dynamically change the upper limit of the subscript of an array at runtime. However, you cannot change the size of the array so that it exceeds the size declared in the DIM statement.
When you run the following code, the upper limits of the subscripts of A changes to 2 and 3.
10 DIM A(10,10) 20 MAT READ A(2,3) 30 DATA 1,2,3 40 DATA 3,4,5
You can do the same with the MAT INPUT statement. Furthermore, if A is a one-dimensional array, you can adjust the size of A to the number of data to be entered from the keyboard using the following code.
MAT INPUT A(?)
When you dynamically change the size of an array, you can use the UBOUND function to determine the current upper limit of subscripts.
By writing IF MISSING THEN EXIT DO in a READ statement, you can exit the DO~LOOP repetition when the data in DATA statements are exhausted. By using this feature, there is no need to manage the amount of data in a program. Compare the following two programs: In programs using FOR~NEXT, it is troublesome to change because the person writing the program has to know the amount of data. Think about what would happen if you had a lot of data. (Don't you want the computer to count the number of pieces of data?)
10 DATA 12,43,54,65 20 FOR i=1 TO 4 30 READ a 40 PRINT a,SQR(a) 50 NEXT i 60 END
10 DATA 12,43,54,65 20 DO 30 READ IF MISSING THEN EXIT DO: a 40 PRINT a,SQR(a) 50 LOOP 60 END
In Full BASIC, the size of the drawing pane is not fixed. It is an instruction system that aims to obtain the same result even if the number of pixels in the drawing pane is different. In Full BASIC, the default shape of the drawing pane is square unless otherwise specified.
In Microsoft BASIC, the coordinate system is based on pixels starting from the upper left edge of the screen, but in Full BASIC, the principle is to draw with a coordinate system defined in the program according to the object to be drawn, rather than using pixels as a unit.
A coordinate system that is virtually defined in a program is called a problem coordinate. Problem coordinates are a concept very similar to N88-BASIC's world coordinates, but N88-BASIC's world coordinates can only define the positive direction of the y coordinates downward, while the problem coordinates of Full BASIC have a standard y-coordinates that is directed upward. ( However, it is also possible to define it downwards.)
The instruction to set the problem coordinates in Full BASIC is SET WINDOW. Parameters are written separated by commas in the order of left x coordinate, right x coordinate, lower y coordinate, and upper y coordinate. The order in which the parameters are arranged is different from the WINDOW statement in N88-BASIC. In the SET WINDOW statement, you first write the range of x coordinates, and then write the range of y coordinates.
Example
SET WINDOW -8,8,-12,12
Let the range of x coordinates be -8~8 and the range of y coordinates be -12~12.
In Microsoft BASIC, the command to draw points is PSET, but in Full BASIC, PLOT POINTS is used.
Example.
10 SET WINDOW -4,4,-1,7 20 FOR x=-4 TO 4 STEP 0.1 30 PLOT POINTS:x,x^2 40 NEXT x 50 END
In the above program, the shape of the dot drawn is *.
Adding the below will change the shape of the dots to ・.
15 SET POINT STYLE 1
Point styles are 1 ・, 2 +, 3 *, 4 ○ ,5 × .
The point style at the start of program execution is 3.
The instruction to draw a line in Full BASIC is PLOT LINES.
Write PLOT LINES: followed by several coordinates separated by semicolons, then draw a polyline connecting them in order. Coordinates are written separated by a comma between the x and y coordinate. For example, when you run the below, a line connecting the points (1,2), (3,4), and (5,6) is drawn.
PLOT LINES: 1,2 ; 3,4 ; 5,6
If you stop the end of the PLOT POINTS statement with a semicolon, the next time you execute a PLOT LINES statement, the last point specified in the first PLOT LINES statement and the first point specified in the next PLOT LINES statement will be connected by a line segment.
Example: Graph of the quadratic function y=x2
10 SET WINDOW -4,4,-1,7 20 FOR x=-4 TO 4 STEP 0.1 30 PLOT LINES: x,x^2; 40 NEXT x 50 END
In Microsoft BASIC, if you write LINE -(x,x^2), you can connect the points specified just before by writing like this, but when you first execute this statement, the lines between the points on the screen are connected by a line segment, and an unintended extra line is drawn. In PLOT LINES, the first point specified is the starting point of the line.
When drawing multiple curves using PLOT LINES, you must break the connection of the polygonal lines in the middle.
This happens if you run PLOT LINES without writing a semicolon at the end, but in that case, you can omit the coordinates . It is exactly the same as the empty PRINT used when breaking a line. In this case, the colon written after LINES will also be omitted.
Example. Graphing the n-th degree functions y=xn (n=1,2,3,4,5)
10 SET WINDOW -4,4,-4,4 20 FOR n=1 TO 5 30 FOR x=-4 TO 4 STEP 0.01 40 PLOT LINES: x,x^n; 50 NEXT x 60 PLOT LINES 70 NEXT n 80 END
When drawing curves using Full BASIC, think of a device called an XY-plotter (pen plotter) in your mind. In an XY-plotter, if you move the pen with the pen down, a line will be drawn. Raising the pen and moving the pen does not draw a line.
In Full BASIC, you can use the PLOT LINES statement to move the pen and raise and lower the pen. When you specify the coordinates, the pen moves to the specified position. The semicolon that separates the coordinates serves to lower the pen. If the end ends with a semicolon, the pen remains lowered. On the other hand, if there is no semicolon at the end, move to the specified coordinates and raise the pen. In particular, the PLOT LINES statement that does not specify coordinates is used for the purpose of raising the pen.
In Microsoft BASIC, AND and OR are numerical operations defined for integers, while AND and OR in Full BASIC is part of the control structure.
Full BASIC does not evaluate q when it finds that p is false in the logical expression p AND q.
Similarly, in the logical expression p OR q, if p is true, q is not evaluated.
So, for example, if the upper limit of the subscript of an array A is 10, evaluating i<=10 AND A(i)=0 when the value of i is 11 does not result in a runtime error. However, Microsoft BASIC calculates the value of A(i)=0 regardless of whether i<=10 is true or false, so the subscript is an error that is out of range.
Full BASIC does not have a syntax for WHILE ~ WEND. In Full BASIC, DO WHILE ~ LOOP is used.
Full BASIC's SELECT ~ END SELECT syntax is grammatically almost identical to that of Quick BASIC and Visual BASIC, but it works a little differently. If you omit CASE ELSE, if there is no matching CASE item at runtime, Microsoft BASIC will do nothing and move on, but Full BASIC will be in an exception state.
There are four types of procedural definitions: function definitions, subprograms, picture definitions, and handlers. Subprograms are sub procedures of Quick BASIC or Visual BASIC. Microsoft BASIC is not equipped with picture definitions or handlers.
There are two types of function definitions, subprograms, and picture definitions: internal procedures and external procedures.
Internal procedures are procedures written within the main program or external procedures, and are broad in scope except for arguments.
External procedures are independent of the main program and other external procedures, and are independent of variables, the data sequence in DATA statements, and channel numbers other than zero (file numbers in Microsoft BASIC).
In Full BASIC, the main program and external procedures are called program units.
In Quick BASIC and Visual BASIC, variables are passed by reference as arguments to function procedures and SUB procedures, but in Full BASIC, they are passed by value in function definitions and by reference in subprogram and picture definitions. Note that Visual BASIC allows you to change the way arguments are passed by writing ByVal or byRef, but Full BASIC does not have a corresponding syntax.
When you want to make an array an argument in Full BASIC, the parameter (formal argument) has dimensions indicated by parentheses and commas.
A() 1 dimentional
A(,) 2 dimentional
A(,,) 3 dimentional
When writing an array as an actual argument, only the array name is written.
When you write an array as an argument to a function, it is passed by value. In the subprogram and picture definition, it is passed by reference. Note that when using an array as a function argument, each function call takes extra time to duplicate the array.
Example 1: Using an array argument in a function definition
100 DATA 23,43,54,61,62,82,90,33,43,15 110 DECLARE EXTERNAL FUNCTION ave 120 DIM a(10) 130 MAT READ a 140 PRINT ave(a) 150 END 160 EXTERNAL FUNCTION ave(a()) 170 LET t=0 180 LET n=UBOUND(a) 190 FOR i=1 TO n 200 LET t=t+a(i) 210 NEXT i 220 LET ave=t/n 230 END FUNCTION
Example 2 Passing an array to a subprogram
100 DATA 23,43,54,61,62,82,90,33,43,15 110 DECLARE EXTERNAL SUB mean 120 DIM a(10) 130 MAT READ a 140 CALL mean(a,m) 150 PRINT m 160 END 170 EXTERNAL SUB mean (a(),m) 180 LET t=0 190 LET n=UBOUND(a) 200 FOR i=1 TO n 210 LET t=t+a(i) 220 NEXT i 230 LET m=t/n 240 END SUB
In Full BASIC, channel numbers other than zero are independent for each program unit, but channel numbers can be used as arguments to external subprograms. The parameters (provisional arguments) are # and integers, such as #1, #2, etc. Actual arguments are specified by # and numeric expressions.
Full BASIC allows you to define modules consisting of multiple external procedures. Modules can have static variables that can be shared from outside the module. You can also define static variables that are shared only within a module. Modules also allow you to declare channel numbers to be shared within the module. Modules can contain initialization code to initialize static variables.
While string variable names are represented by adding $ to the end, and string constants are represented by double quotes, the way strings are handled is quite different from Microsoft BASIC. And more, there is no variant variable that can be assigned as either a string or a number, as in Visual BASIC. Numeric and string data are syntaxically distinct.
In Full BASIC, the string concatenation operator is &. In Microsoft BASIC, "2"+"3" becomes "23", but in Full BASIC, the same is written as "2"&"3". In Visual BASIC, you can use & for string concatenation, but in VB, "2"+3 becomes 5, so VB need a different operator to perform operations on the string. In the case of Full BASIC, there are no grammar problems, but the fact that "2"+"3" becomes "23" is misleading to beginners, so Full BASIC does not allow it to be written that way.
In Microsoft BASIC, the basic string processing function is the MID$ function, but in Full BASIC, the basic function is to specify a substring of a string variable. For the string variable s$, s$(m:n) represents the string from the mth character to the nth character of s$.
The MID$ function allows you to manipulate string expressions, while Full BASIC substring specifications target string variables. Therefore, when you want to extract a substring from the calculation result of a string expression, you must first assign the value of the string expression to a string variable. If this is not possible, you can use the MID$ function just like in Microsoft BASIC by adding a DEF statement like this:
DEF MID$(s$,m,n)=s$(m:m+n-1)
Note. The latest version of Decimal BASIC provides the MID$ function as a supplied function.
In Microsoft BASIC, the MID$ function can be written on the left side of the assignment statement to replace the string, but in Full BASIC, the substring specification is written on the left side of the assignment statement. For example,
MID$(s$,4,2)="xy" Microsoft BASIC
LET s$(4:5)="xy" Full BASIC
Assignments to MID$ in Microsoft BASIC do not move any characters other than the specified position, but assignments to string variables with substring specifications in Full BASIC will change the overall length if the length of the string being assigned is inconsistent with the length of the specified part. For example,
when s$="12345",
MID$(s$,2,2)="a" ⇨⇨ s$="1a345",
LET s$(2:3)="a" ⇨⇨ s$="1a45",
MID$(s$,2,2)="abcd" ⇨⇨ s$="1ab45",
LET s$(2:3)="abcd" ⇨⇨ s$="1abcd45".
Full BASIC uses this property to allow you to add or remove parts of a string.
For example, when s$="12345", LET s$(2:4)="" brings s$="15".
In the substring specification s$(m:n), when n is less than m, it is a promise that represents the empty string immediately before m. Therefore, executing
LET s$(n:n-1)=t$
t$ is inseted just before the nth character.
For example when s$="12345", LET s$(3:2)="ab" brings s$="12ab345".
That is, when m-1≦n, LET s$(m:n)=t$ means s$ = LEFT$(s$,m-1) + t$ + RIGHT$(s$, LEN(s$)-n)
The Full BASIC standard has three level modules depending on the type of files it can handle: core, enhanced internal, and enhanced native.
The files supported by the current version of Decimal BASIC are core.
There are three types of files that can be used at the core module: display format files, sequential internal format files, and stream internal format files. Display format files are regular text files, while ordered internal format files are sequential files that are read and written using WRITE and READ statements. A stream file is a file in which one piece of data is recorded per line.
| Microsoft BASIC | Full BASIC |
OPEN "ABC.TXT" FOR INPUT AS #1 | OPEN #1: NAME "ABC.TXT" ,ACCESS INPUT |
OPEN "ABC.TXT" FOR OUTPUT AS #1 | OPEN #1: NAME "ABC.TXT" |
OPEN "ABC.TXT" FOR APPEND AS #1 | OPEN #1: NAME "ABC.TXT" ,ACCESS OUTPUT |
Microsoft BASIC has three access modes: INPUT, OUTPUT, and APPEND, but Full BASIC has three access modes: OUTIN, INPUT, and OUTPUT. Full BASIC's INPUT mode and Microsoft BASIC's INPUT mode are almost the same. Full BASIC's OUTPUT mode is compatible with Microsoft BASIC's APPEND mode. When performing processing corresponding to Microsoft BASIC's OUTPUT mode, after opening the file in access mode OUTIN, execute the ERASE statement to erase the file contents and then start writing.
In Full BASIC, the default value for access mode is OUTIN (which can be omitted). Files opened with OUTIN can also be used for input. You can also add and write by moving the file pointer to the end.
In Microsoft BASIC, it is common to access files by looping WHILE NOT EOF(n) ~ WEND, but Full BASIC does not have an EOF function (note that the EOF function in Microsoft BASIC is a function of the result being a number). Full BASIC reads files using the same techniques as reading from a DATA statement.
10 OPEN #1: NAME "readme.txt" 20 DO 30 LINE INPUT #1, IF MISSING THEN EXIT DO: s$ 40 PRINT s$ 50 LOOP 60 CLOSE #1 70 END
In writing to a file, once the file is opened, an ERASE statement should be executed.
10 OPEN #1: NAME "A:SQRTABLE.TXT" 20 ERASE #1 30 FOR i=1 TO 10 40 PRINT #1: i,SQR(i) 50 NEXT i 60 CLOSE #1 70 END
Without the 20-line ERASE statement, if the file "A:SQRTABLE.TXT" already exists, it will be overwritten from the beginning of the file, resulting in an error.
If you want to append to the file, change the 20 line as follows.
20 SET #1:POINTER END
In Full BASIC, you can use an internal format file to read data written in a WRITE statement as a READ statement.
In addition, decimal BASIC uses CSV as the internal format. Therefore, if you export it in internal format, you will get almost the same output as the WRITE statement of Microsoft's BASIC.
Writing program
100 DATA "Alice", 56, 74 110 DATA "Ichiro", 92, 83 120 OPEN #1: NAME "A:sample.CSV",RECTYPE INTERNAL 130 ERASE #1 140 DO 150 READ IF MISSING THEN EXIT DO: s$, x,y 160 WRITE #1: s$,x,y 170 LOOP 180 CLOSE #1 190 END
Reading program
10 OPEN #1: NAME "A:sample.CSV",RECTYPE INTERNAL 20 DO 30 READ #1,IF MISSING THEN EXIT DO: s$, x,y 40 PRINT s$,x,y 50 LOOP 60 CLOSE #1 70 END
Note: If you open a file without specifying a RECTYPE, it will be considered to have been opened in a display format. In a file opened in display format, the WRITE statement behaves the same as the PRINT statement.
In Microsoft BASIC, in the PRINT, INPUT, READ, and WRITE statements, the next to the file number is a comma, but in Full BASIC, it is a colon.
Exsample.
PRINT #1: x,SQR(x)
INPUT #1: A,B
LINE INPUT #1: s$
When adding formatting to a PRINT statement, write a USING clause separated by a comma before the colon.
PRINT #1,USING "### ##.###": a,b
For more information about differences with Microsoft BASIC, see "Differences from Other BASICs" in BASIC Help