Last Edited: 01 May 2008 by superuser
Importered from old WiKi -- 30/04-08 18:04.

HOWTO use BASIC in Puppy

Yes, there is BASIC hidden in Puppy (versions 1.0.5 and 1.0.6)!

PuppyBasic is the new name for WxBasicscript, which is a simplified version of WxBasic.

EXAMPLE

From the desktop, click on the <console> icon, to get a command line.

This command tells PuppyBasic to take the program directly from the keyboard:
# puppybasic /dev/tty

Now you can enter your program:
print "Hello World"

On the next line, just enter CTRL-D to finish entering the program. Then the program will run immediately!

STORE A PROGRAM

That is actually a good way to try some simple commands, to see quickly how they work. But you will soon want to use an editor for your programs.

Change to a temporary directory:
# cd tmp

Make a program file:
# leafpad hellow

In the editor, enter the file and save and exit:
' My first program
print "Hello World"
print 2+2
print "Goodbye"
end

Now you can run the program:
# puppybasic hellow

Program development tip:
For quickly making changes and testing them, use the up-arrow key on the command line, to access your previous commands to use the editor or run the program.
For some reason, it does not seem to work to leave the editor open while you try out program changes. But if you open the editor in another one of your four "workspaces", then you can leave it open -- just Save and switch to the console in the other workspace to try it out.

If you have not used BASIC since the 1980's, the line numbers and REM statements seem to be gone, so you will have to brush up on this version.

Use the desktop FIND command to search for files containing wxbs in their names, to see complex examples in Puppy.

HOW FAST IS IT?
Although it is called an interpreter, it is not as slow as old-fashioned interpreters that processed and executed each line one at a time. Instead, the text of the BASIC program is processed into a tokenized parse tree, which is then executed fairly efficiently. An empty FOR loop takes about 1 microsecond per iteration on a PII-266. (All arithmetic seems to be done in floating-point -- there is no speed advantage in trying to use integers.) A simple arithmetic-calculation and assignment takes about 6 microseconds. A simple string concatenation takes about 8 microseconds. So it is fast enough to do a fair amount of calculation in a reasonable amount of time -- it should execute over 10,000 lines of BASIC per second typically, once it finishes tokenizing the text.

You can learn more at:
PuppyBasic
WxBasic
http://noforum.de/wxBasicscript-documentation/wxbasic/frameset.htm
http://noforum.de/wxBasicscript-documentation/wxbasicscript/index.htm

http://www.murga.org/%7Epuppy/viewtopic.php?t=2349
http://www.murga.org/%7Epuppy/viewtopic.php?t=2457
http://www.murga.org/%7Epuppy/viewtopic.php?t=2339
(There is supposed to be an automatic system of executing BASIC programs in Puppy, based on naming files with .wxbs extensions, but it does not seem to work for simple command line text programs.)



CategoryDevelopment