Wednesday, June 11, 2008

Compatibility Step 7

Another step towards running "Hunt the Wumpus" on Quite BASIC! :)

Today I added conditional GOTO to the language. I did it with mixed feelings because it is one ugly construct, but many early BASIC programs did use it.

So, now you can do things like:
10 LET R = 1 + RND(3)
20 ON R GOTO 100,200,300

That little code snippet will randomly make the program go to either line 100, 200, or 300.

Oh, and I also added the INT(x) function. It is the same as the existing FLOOR(x), but INT(x) is the name that classic BASIC programs used.

Sunday, June 01, 2008

Compatibility Step 6 -- Multi dimensional Arrays

This one was not straight forward because javascript doesn't have a simple syntactic construct to create a multi dimensional arrays. As of today though, QuiteBASIC has just that. For example:

10 DIM A(5,6,4)

declares a 3D array.

The array can then be used in LET commands and in expressions just like you expect it to. For example:

20 LET A(1,2,3) = 64
30 PRINT SQR(A(1,2,3))

will print 8.

This only works with the DIM command. The ARRAY command just declares a 1D array of dynamic size. And this only works with the parenthesis syntax for array indices. So A[1,2,3] is a syntax error.

I also added the TAB(x) function which is typically used in PRINT commands to format the output. For example:

40 PRINT TAB(5); "Hello!"

will print five spaces followed by "Hello!".