[net.lang.forth] forth83 query

cmaz504@ut-ngp.UUCP (03/17/84)

I recently got a copy of the Forth83 standard on my Kaypro and would like
to know how to create and save files with it. Unfortunately there were no
instructions and I'd like to do some real programming in Forth rather than 
having to start from scratch each time. Any help would be appreciated.

Steve Alexander
cmaz504 at ut-ngp

wmb@sun.uucp (Mitch Bradley) (03/22/84)

By F83, I mean the public-domain version of Forth83 that was done my
Michael Perry and Henry Laxen.

F83 uses CP/M files to contain Forth screens.  It does not have a
general-purpose stream-oriented file interface like Unix has.
N.B. I have written a "stdio"-like stream-oriented file interface for
F83 and will post it to the net when I am satisfied with it.  For more
information, see the 2 papers by W.M. Bradley (me) in the Proceedings
of the 1983 Asilomar FORML Conference.

Now for how to manipulate files in F83.  This is not an exhaustive
tutorial, but merely something to get you started.

F83 has a notion of a "current file", to which nearly all file
operations apply.  The variable FILE contains a number which refers to
that file (actually, it contains the address of a CP/M file control block
for that file).

Stack notation:

Following the usual convention, (S in1 in2 -- out1 out2 out3 )
means that the word expects 2 input arguments on the stack and leaves 3
output results on the stack.  If the word also takes a name from the
input stream, this notation is used: (S in1 in2 --name out1 out2 out3 )
Note the absence of a blank between the hypens and "name".

Glossary:

MAKE-FILE (S --name )
	Create a file on the disk with the given name.  The file is
	initially empty.  The file must be "OPEN"ed before further use
	may be made of it.  Example:  MAKE-FILE B:MYFILE.SCR

CREATE-FILE (S #blocks --name )
	Create a file on the disk with the given name.  The file is
	initially #blocks * 1024 bytes long and contains blanks.
	The file must be "OPEN"ed before further use may be made of it.
	Example: 30 CREATE-FILE B:MYFILE.SCR

DIR (S -- )
	Show a list of the files on the disk.

OPEN (S --name )
	The named file becomes the current file.  The first time a file
	is "OPEN"ed, a dictionary entry for the file is created, so
	that the file may be subsequently opened just by using its name.
	The file has to already exist on disk (see MAKE-FILE and
	CREATE-FILE).  Example:  OPEN B:MYFILE.SCR
	Later, the file may be re-opened by simply typing B:MYFILE.SCR



Once you have made a file current by OPENing it, all of the normal
Forth I/O words (BLOCK, LOAD, THRU, LIST, etc ) refer to blocks within
that file.  You can edit the blocks with the editor (see Starting Forth
by Leo Brodie for a description of how to use the editor).
SAVE-BUFFERS will write out to disk any blocks you have changed.

Copying files:

The normal CP/M utilities (e.g. PIP) will work for copying files around.
From within Forth, you can also copy files.  Here's an example:

OPEN NEWFILE.SCR
FILES FROM OLDFILE.SCR  5 10  TO  20  CONVEY
FORTH

will copy blocks 5 through 10 of OLDFILE.SCR to NEWFILE.SCR, starting
at block 20 in NEWFILE.


There is more that can be done, but I don't have time right now to
write about it.  I learned all this by reading the code and the shadow
screens.

				Mitch Bradley
				Sun Microsystems, Inc.
				decvax!decwrl!sun!wmb