\documentstyle[a4,epsf,alltt]{article}
\begin{document}


\include{commands}


\title{Introduction to the editor}
\author{Jocelyn Ireson-Paine}
\maketitle


\section{The Ved editor}

In the handout on {\it How to run Eden}, I showed you how to use the
control commands like \verb/y/, \verb/r/ and \verb/s/. I also mentioned
that there is an \verb/e/ command for ``editing'' the world --- that is,
for changing it as Eden runs.

In general, an editor is a program for creating and modifying files.
Word-processors on PCs and other microcomputers are editors, though they
have a lot of specialised text-handling facilities that aren't found in
other editors. You will need an editor not only for modifying the
worlds, but --- more importantly --- for writing your own brains, so
this is the next thing to learn. Each computer system comes with its own
editor. Although basic concepts such as cursor movements don't
vary between editors, the details of what commands to give do.
We shall be using the {\it Ved} editor, written by Sussex University and
built into this version of Prolog. Even if you know how to use
WordPerfect or some other word-processor, you won't be able to use the
same commands with Ved. However, some of the ideas will be similar.

As with the Eden handout, the best thing to do is to read these notes
once without trying anything, and then go through again, this time
working all the examples.


\subsection{Starting Ved from Prolog}

First, start up Eden Prolog if necessary. Remember that the command,
from VMS, is just \verb/eden/. You should then get a \verb/?-/ prompt.

Next, type
\begin{verbatim}
teach vedprpc
\end{verbatim}
Note: this is an unusual command, because you {\it don't} need to end it
with a dot. For reasons best known to Poplog's implementors, this is
true of all the commands for starting editing from Prolog. However, you
do need the RETURN after it.

Once you have done this, you will see the first part of a file displayed
on the screen, which gives you instructions on how to continue. Work
through it carefully, and ask if you have any trouble. Note these
important points before starting. Firstly, the file assumes you are
working from CTC. If not, the keys it describes won't work. Ask me for
help. Secondly, it refers in several places to the \verb/prolog/
command, used to start Prolog from VMS. We are using a different
command, \verb/eden/, because we want the Eden simulator to be loaded
into Prolog. So wherever it says \verb/prolog/, type \verb/eden/.


\subsection{Another TEACH file}

In Poplog jargon, these instructional files that the editor displays are
called {\it TEACH files} (or sometimes {\it HELP files}). There is
another TEACH file which continues where \verb/vedprpc/ left off. This
is \verb/vedprpc2/. Once you are happy with the stuff in the previous
section, get into Prolog, and then type
\begin{verbatim}
teach vedprpc2
\end{verbatim}
Follow the instructions as before. Once again, where it talks about the
\verb/prolog/ command, use the \verb/eden/ command instead.

At the end of this file, you'll be told that you can go on to
\verb/ved3/. Whether you do so is up to you. It contains some useful
stuff such as how to search for particular strings, and if you're happy
with Ved so far, by all means learn these extra commands. However, you
can get by without them, so you may prefer to leave them for the moment.               


\subsection{Editing the world}

You now know enough to try out the Eden control command \verb/e/. Get
into Eden Prolog, and start a new life:
\begin{verbatim}
eps( psbug2, psworld2 ).
\end{verbatim}

Then run it for 12 cycles, until the bug has put the coin in the slot
machine, causing a piece of food to appear. You can do this in various
ways. The quickest is to give the control command \verb/-/ and RETURN,
to turn off the view window; and then \verb/s/, space, \verb/200/
and RETURN, to run forward 12 cycles. But if you wanted, you could
single-step until the food appears, by repeatedly pressing \verb/y/ and
RETURN.

When the food appears, type \verb/e/ and RETURN. The cursor will then
move to somewhere within the world. Move it until it is over the
\verb/+/ symbol, to the left of the \verb/S/. Then type a space. This
will overwrite the \verb/+/. Then move the cursor over the \verb/S/, and
type a \verb/+/. You have now replaced the slot-machine with a piece of
food. Can the bug cope?

To end the edit, do ENTER \verb/x/, as described in the TEACH file. This
preserves the changes in the world and goes back to Eden. Now
single-step through with \verb/y/ and watch the bug. 

If, while editing, you decide you don't want to change the world, quit
the edit with ESC q. Again, this was described in the TEACH file.

Note: the behaviour of the world-editor is slightly different from that
you are now used to. When you type a character, it {\it overwrites} the
character beneath it, rather than pushing the rest of the line to the
right. This is called {\it static} mode. I use it in the world-editor
because it's convenient there. However, it's less useful in updating
text files, which is why I haven't mentioned it before or implemented
it elsewhere.

You can try making other changes to the world. Most of the time, the bug
will not be able to cope --- not surprising, given the simplicity of
its rules.


\subsection{Editing the view window}

This, done with the \verb/v/ command, is mainly useful if a lot of
diagnostic output is produced, and flies past so quickly that you want
to go back and look at it again. It's also handy for making a printed
copy.

To demonstrate \verb/v/, get into Prolog and start a new life. This
time, do not use the \verb/-/ command: you will need some view output to
experiment with! Then run the bug for a few cycles, say 10.

When it stops, type \verb/v/ and then hit RETURN. The cursor will move
into the view window, just after the last piece of output. You can then
move it up and down to bring any part of the window into sight, using
any of the edit commands you already know. You can expand the window to
cover the whole screen by hiting ESC \verb/w/, as described in
\verb/vedprpc/. Note that it's also possible to change the window by
typing into it. I don't advise this though, since it will scramble
future view output for the same life.

When you have finished, end the edit with ENTER \verb/x/ or ESC
\verb/q/. The cursor will then jump back to its old position, and Eden
will be ready for the next control command. You can then run the bug
from where you left off.

To print the window, give the command ENTER \verb/ctcprint/ RETURN while
you are editing it. The output so far will be printed on the CTC
printer. You can also use the other printing commands described in
\verb/vedprpc2/ to print on the other printers.


\subsection{Looking at bug brains}

The text of the standard bug brains I've written is stored as library
files. You can run them in Eden, but because they're not held in your
directory, you need a special Ved command to look at them. This is the
\verb/showlib/ command. You use it like \verb/teach/ and \verb/ved/, by
typing it in response to the \verb/?-/ prompt. Thus,
\begin{verbatim}
showlib psbug1
\end{verbatim}
will show you the rules used in the production-system bug \verb/psbug1/.
Try that now. As with \verb/ved/ and \verb/teach/, you don't need a dot
after the filename. When you've finished, return to Prolog with ESC
\verb/q/.

You should remember that the section on {\it Other TEACH files} in
\verb/vedprpc/ showed you how to temporarily transfer to another TEACH
file, with the command
\begin{verbatim}
ENTER teach window RETURN
\end{verbatim}
as an example. You can do the same with \verb/showlib/, using it from
the Ved command line. Try that now.


\end{document}
