*********************************************************
*                                                       *
* PISTOL-Portably Implemented Stack Oriented Language   *
*                       Version 1.3                     *
* (C) 1982 by   Ernest E. Bergmann                      *
*               Physics, Building #16                   *
*               Lehigh Univerisity                      *
*               Bethlehem, Pa. 18015                    *
*                                                       *
* Permission is hereby granted for all reproduction and *
* distribution of this material provided this notice is *
* is included.                                          *
*                                                       *
*********************************************************

     BRIEF, PRELIMINARY DOCUMENTATION ON PISTOL 1.3:

               (updated February 24, 1982)

       PISTOL is a Portably Implemented Stack Oriented
Language that has been developed for general use and
experimentation. It is at an early developmental stage and so
may have lots of "bugs". I would appreciate any comments and
suggestions.  For the DEC-20, it has been implemented in
PASCAL;  for CP/M, it has been implemented with the BD Software
C compiler v1.4.

       PISTOL resembles an HP calculator in many ways.  It
uses a (parameter) stack to pass numbers between routines.  The
language is "RPN", that is Reverse Polish Notation.  At
present, all arithmetic is performed in integer form.  This
language was inspired by and has evolved from two mini- and
micro- based languages, FORTH (Charles Moore, 1970) and STOIC
(MIT and Harvard Biomedical Engineering Center, 1977).


GETTING STARTED
======= =======
       Before describing the language further, this is how to
"bring it up":

type
       DIR CORE1 to see if this file exists, otherwise, type
       DIR PBASE to make sure this file exists.


type
       EXE PISTOL.PAS
(and for the DEC-20):
link TTY: to the input.

       PISTOL should come up with:

***PISTOL 1.3***
X>

       To make it smarter, it can be "educated" with a set of
useful definitions already prepared in a file named, CORE1 or
PBASE ; to do this type:

X> 'CORE1 RESTORE       (only if CORE1 exists!)
or
==

X> 'PBASE LOAD          (if PBASE exists; this is much slower)
X> 'CORE1 COREDUMP      (creates CORE1 for future use)


TUTORIAL:
=========

       Before discussing some examples and features, it is
probably best to understand the "prompt".  The prompt is what a
program types at the beginning of the line when it is awaiting
input from the user.  The prompt supplied by PISTOL can be
several characters long and it is to inform or remind the user
about the "state" of the program.  If a number appears at the
beginning of the prompt, it signifies that the parameter stack
is not empty.  Next, a letter is displayed (such as "X") that
indicates the current number base used for i/o ("X", the Roman
numeral for "10", signifies decimal). After this letter there
may be other characters or symbols that are used to indicate if
you are in the middle of some syntactical construction.
Finally, the ">" completes the prompt expression.  In the
examples supplied above and below we have attempted to suggest
the typical prompts that one might expect to see.

       After educating PISTOL by loading PBASE or by restoring
CORE1, the system is "smarter" you can try the following
examples:

X> 1 2 23 STACK

The system takes each number as encountered and places them on
the stack.  The word, STACK , prints the current contents of
the stack without changing the stack in any way.

       Now try typing:
3X> + STACK

This should result in the addition of the top two members of
the stack (2 and 23) and placing the result (answer 25) back on
the stack. The word STACK then displays the current contents of
the stack.

       Now try typing:
2X> * stack

The top two items of the stack will be multiplied together and
the result left on the stack.  The word, "stack" is interpreted
as STACK, and we see that the only thing in the stack is the
answer 25.

       To disable the automatic interpretation of lowercase
as uppercase, type:

X> RAISE OFF (or "raise off")

and successive lines will be interpreted without conversion of
lowercase to uppercase.  To revert to conversion, type:

X> RAISE ON

       There are a number of different options that can be
invoked such as ECHO ON and ECHO OFF which control the listing
of files read in by the '<filename> LOAD operation.  One can
use CONSOLE ON and CONSOLE OFF to determine what reaches the
terminal.  An error condion will automatically restore output
to the terminal.  LIST ON and LIST OFF will determine what
output will also be routed to the output list file(of course a
listfile has to be declared first).  This is useful to have a
more permanent record of what happened during a session.  There
is also a SHOWCODE and a NOSHOWCODE which will show the results
of compiling each input line (that is for those who want or
like to know what is going on behind the scenes).

       On the DEC-20 (and also in CP/M) one can exit from
PISTOL by using a control-C, but a more "refined" way is to
type the word, BYE, which will return you to the operating
system.

       PISTOL can examine the contents of its own (virtual)
memory. The W@ ("fetch") operator is similar in spirit to the
PEEK function in BASIC.  To place the contents of a memory
location on the stack one simply places the address on stack
and then types W@ .  For example, if we want to place the
current value of RADIX, the base used in all I/O number
conversion, we need to find the value stored in the RAM
location at -1 (i.e. what is RAM[-1]?) we can type:

X> -1 W@

which will place the desired information on stack.  The inverse
operation, which is more dangerous(because a mistake can crash
the program), is to store a new value in the RADIX, hence
change the number base.  The operator, W! ("word store"),
performs this function(for this example we suppose that the
RADIX address is -1, usually, it is not):

X> 16 -1 W!

would convert PISTOL to converse in hexadecimal.

       Of course it is aukward to remember constants, such as
the address of RADIX so we can define such constants by:

X> -1 'RADIX CONSTANT

After such a CONSTANT definition we can redo the examples that
use W@ and W! by (RADIX is in fact already defined in PBASE):

X> RADIX W@
and
X> 16 RADIX W!

       As an additional convenience the user can define space
for variables with the word, VARIABLE.  For example, If you
wish to define a variable with the initial value 0 and named
ANSWER, you should type:

X> 0 'ANSWER VARIABLE

Later, if you wish to perform the PASCAL statement:

ANSWER := ANSWER + 1;

you would write the PISTOL code:

X> ANSWER W@ 1 + ANSWER W!

Notice that you MUST choose an initial value in VARIABLE and,
of course, CONSTANT definitions.

       Just like the convenience feature of PASCAL,
for which one can use SUCC(ANSWER) to increment ANSWER
by one, there exists an analogous operator (or you can
define your own!):

X> ANSWER 1+W!


       The language has many resources beyond those presented
so far.  Perhaps the most significant is the ability to define
new words or definitions to make the language increasingly
smarter. Try examining the contents of the file, PBASE , to see
how the definitions may be formed.  As a complex example, the
word, = is defined whose function is to take the top item off
of the stack and print its value.  For example, typing:

X> 8 8 + =

will cause the system to respond with the answer: 16.  Note
that this calculation causes no net change to the stack(it is
the presence of a number before "X>" that indicates the number
of items in the stack at that moment); its contents before the
first "8" was typed is the same as its contents after the
system responds with 16.  Thus the definition of the word = has
increased the convenience of the system for arithmetic
calculations.

       The system can and does handle strings.  Suppose you
would like the system to output "HELLO".  Try typing:

X> 'HELLO MSG

The system will take the 'HELLO as a string to be placed upon
the stack.  The MSG ,"message" takes the top item off of the
stack, assumes it to be a string, and prints it.  The stack
contains the same stuff after MSG is executed as before the
'HELLO was typed.

       Useful I/O words are CR which will output a carriage
return and line feed sequence.  The word SPACE will output a
space. And the word SPACES will pop the top of stack to obtain
the number of spaces to be output.  For example:

X> 'HELLO MSG SPACE 'HELLO MSG CR 5 SPACES 'BYE MSG

should produce:

HELLO HELLO
    BYE


       Standard output would be most tedious if we could not
create definitions to speed up programming.  Here is a humorous
example:

X> 'HELLO : 'HELLO, MSG SPACE 'YOURSELF! CR ;

The use of : and ; provide the means to define a new word
"HELLO" Later, you can type:

X> HELLO

and the system will respond:

HELLO, YOURSELF!

       Thus we see that the pair of symbols, ":" and ";"
delineate a structure used to make definitions.  The material
in between the two symbols becomes the definition of the word
whose name is the string that was lastly placed on the stack
before the ":".

       One can create strings with embedded blanks and tabs up
to 127 characters long by using double quotes to delineate both
ends of the string.  For example, the word, HELLO, defined
above, could have been defined:

'HELLO : "HELLO, YOURSELF!" MSG CR ;

Even with RAISE ON, lowercase characters within double
quotation marks will not be converted.

       There are other types of structures.  The pair of
words, DO and LOOP permit an iterative structure.  They use the
top two quantities on the stack as limits of iteration.  So:

X> nn n DO ... LOOP

is equivalent to the PASCAL structure:

       FOR  I := n TO (nn-1) DO
               BEGIN ... END;

To place the current value of the iteration variable on the
stack one uses the word, "I" .  Here is an example that you can
try:

X> 'COUNTING : CR 1 + 1 DO I = SPACE LOOP ;

X> 10 COUNTING
and see PISTOL counting to 10.

       An alternative terminating word to this structure is
+LOOP.  If one uses in PISTOL:

       nn n DO ... m +LOOP
one simulates the BASIC structure:

100 FOR I=n TO (nn-1) STEP m