[][src]Module basic::_Introduction

Introductory Tutorial

Begin by opening a terminal and running the executable. Double clicking the executable from a GUI desktop often works as well. If you get the following, you have achieved success and are ready for this tutorial.

   64K BASIC
   READY.
 > █

Type CTRL-D to exit 64K BASIC. Stop a running program with CTRL-C.

64K BASIC is interactive just like it was back in 1964 when the idea of an ordinary person sitting in front of a terminal and directly interacting with a computer was revolutionary. A primary design goal for 64K BASIC is to capture that experience. Except with better error reporting and a modern input system.

When you see the READY. prompt, 64K BASIC is ready to accept a statement. A statement describes the work you want the computer to do. Let's tell the computer to print something. For this tutorial, I'll mark lines that you type with a ">". I'll may not include every READY. every time after this. Go ahead and try your first statement. Type in the marked line followed by ENTER.

   READY.
 > print "Hello World"
   Hello World
   READY.

Entering a statement which executes immediately is called direct mode. To make more interesting programs, we'll have to assemble many statements together into a program. Next, we'll put the same statement into a program by assigning it to a line number. To do this, simply preceed the statement with any decimal integer between 0 and 65529 inclusive.

 > 10 print "Hello World"

Nothing happens. This is called indirect mode. The statement is saved to be executed later. Let's try a couple new statements. LIST will list the program. RUN will run the program.

 > LIST
   10 PRINT "Hello World"
   READY.
 > RUN
   Hello World

Now that we have a program in memory, we can add more lines or edit existing lines. To edit a line, type the line number and press TAB. The line will be loaded into the input buffer for you to edit.

 > 10{TAB}
 > 10 PRINT "Hello World"█

Linux users may have already noticed the input system is based on readline and even reads your inputrc file. Feel free to explore these capabilities, but for now you only need the basics like TAB, BACKSPACE, and the arrow keys.

You may be working out a problem in direct mode which doesn't succeed on the first try. You can access a history of direct mode statements with the up/down arrows.

 > PAINT "Hello World"
   ?SYNTAX ERROR
 > {UP}
 > PAINT "Hello World"█

You can SAVE a program to the filesystem or LOAD one that you previously saved or downloaded. Filenames are specified absolute or relative to the current directory of your operating system when 64K BASIC was started. The NEW command erases the program in memory.

 > 10 print "Hello World
 > save "hello.bas
   READY.
 > new
   READY.
 > list
   READY.
 > load "hello.bas
   READY.
 > list
   10 PRINT "Hello World"

Let's create a multi-line program for the last example of this tutorial. The program will ask the user for a number, print its square root, and repeat indefinitely. Because this is an infinite loop, the program will run forever or until it's interrupted. Typing CTRL-C interrupts a program.

 > 10 input "Your number"; a
 > 20 print "The square root of" a "is" sqr(a)
 > 30 goto 100
 > run
   ?UNDEFINED LINE IN 30:9
 > list 30
 > 30 GOTO 100
   READY.
 > 30 GOTO 10 {Remember you can use TAB here}
 > run
   Your number? -8
   The square root of-8 is NaN
   Your number? 9
   The square root of 9 is 3
   Your number? {CTRL-C}
   ?BREAK IN 10
   READY.

Line 30 was intentionally wrong to demonstrate a compiler error. 64K BASIC has two types of errors, compiler errors and runtime errors. A lot more information is available at compile time which enables underlining the offending section when listing a program. Runtime errors will only display the line number.

This concludes the introductory tutorial. The remainder of this manual is reference material covering everything 64K BASIC can do. There's a lot of programs which will run without modification, but every implementation of BASIC has quirks. Appendix A has information about these quirks and suggestions for converting them to the 64K BASIC dialect.