This document contains a minimal overview of the language CAT, the
(almost pure) functional language used to implement BADNOP.
First of all, this language is almost the same as Joy, with a slightly
different syntax and some extensions that make it easier to apply to
practical problems. You can find more information about Joy at:
http://www.latrobe.edu.au/philosophy/phimvt/joy.html
1. basic ideas
--------------
CAT is a language which bridges functional programming and imperative
programming. In essence, CAT is a functional language, which means it
has no 'real' assignments. Because of its concatenative nature, it can
be read as an imperative language like forth.
However, CAT does have emulated assignments, or 'functional
assignments'. It is possible to assign values to names. More
specificly, hierarchical names. Programs are just values in that
sense.
The main difference between a pure imperative language is that these
assignments do not use mutation. An assignment updates the purely
functional data structure (tree) representing the name space, but
preserves it indefinitely. Practically, untill it is no longer
accessible in which case it is garbage collected.
A consequence if this is that in any case, a function invocation can
be made in such a way that side effects (changed values associated to
names) are guaranteed not to occur as a net result. However, nothing
prevents a function to make a copy of the environment and change it
temporarily.
This illustrates the most important difference between Joy and CAT. In
joy, symbol bindings are permanent. Before a program runs, all symbol
bindings are known. In a CAT program, new values can be assigned
(temporarily) to names using the '!' word.
The exception is that I/O in CAT is not functional, and is implemented
as permanent side effects. In that sense CAT is more like Scheme than
Haskell. I am not getting into monads yet. This is mainly a practical
issue to keep some things simple.
2. help
-------
CAT is interpreted. Code is stored symbolicly. This enables it to be
self documenting to a large extent. To see a list of commands, type
words p
The command 'words' stores on top of the parameter stack a list of all
names in the current environment, and the word 'p' prints the element
on the top of the parameter stack. The parameter stack is thus used to
pass data frome one piece of code to another.
To look at the implementation of a word, type something like
(2dup) see
This result in a printout of the code implementing the word '2dup',
which is '2dup --> over over'. It is possible to put more than one
word in the list, like
(2dup nip) see
Which prints out the previous code, and the code for 'nip'. If the
word is documented, you can access its documentation as
(nip) help
This gives a description in the form: