Search                        Top                                  Index
TEACH LMR                                 Revised Aaron Sloman Sept 1987

Load Marked Range (LMR)

This teach file tells you how to mark a range in a program file and
then get POP-11 (or whichever language you are using) to LOAD it. I.e.
the compiler takes the text from the marked portion of your file and
compiles it, obeying any instructions, or giving you an error message
if you have made a mistake.

Before reading this you should first have read TEACH MARK in order to
learn how to mark a range using the MARKLO and MARKHI keys.

CONTENTS - (Use <ENTER> g to access required sections)

 -- The <ENTER> lmr (Load Marked Range) command
 -- Using CTRL-d instead of <ENTER> lmr
 -- Marking and compiling a longer range
 -- Run time errors
 -- Compile time errors
 -- Looking back at the error message
 -- Finding out what an error message means
 -- Undeclared variables
 -- You can give commands in the output file too
 -- USE <ENTER> w FROM TIME TO TIME
 -- Diverting output to a different file
 -- Related documentation

-- The <ENTER> lmr (Load Marked Range) command -------------------------

If you have part of a file which you'd like to have compiled (loaded)
without leaving VED, you can mark it with the MARKLO and MARKHI keys.
The former is used to mark the beginning of the range (LOw line number),
the latter to mark the end  to (HIgh line number). Having marked a range
you can then get the computer to Load it, with the LMR command.

For example, mark this line (a command to print out the result of
adding 1 to 9999):

    9999 + 1 =>

Then give the command
    <ENTER> lmr

Because something is to be printed out, VED will create a file called
'output' or read one in from the disk if you already have a file with
that name. Then the result will be printed in the file. Try changing the
numbers then repeating the <ENTER> lmr command. As long as you make no
mistakes, the answer should be printed out each time in the 'output'
file.


-- Using CTRL-d instead of <ENTER> lmr --------------------------------

If you wish to avoid having to give the <ENTER> lmr command (which
requires requires pressing keys 5 times) you can tell VED to load the
marked range by pressing the LMR key. This is probably not marked on the
keyboard map because it is usually not a special key, but CTRL-d. What
this means is that, after marking the required range, you should
    Press the CTRL key AND HOLD IT DOWN, then
    Press the "D" key (but DON'T hold it down: just tap it once)

E.g. mark the next line then try the CTRL-d command as described above:

    length([apple banana carrot]) =>

This will cause the length of the list to be printed in the output file.
Try putting another word between the square brackets (but make sure it
is separated by a space from the other words). Then redo the command, to
get the new length printed out.


-- Marking and compiling a longer range -------------------------------

Three lines of POP-11 program follows below. Mark the lines with the
range keys, MARKLO and MARKHI. Then type CTRL-d. You'll see the print
out appear in the 'output' file. Mark the line with 'vars' as the
beginning of the range, and the line with 'x=>' as the end, then type
CTRL-D (i.e. hold CTRL-button down, and press the D key).

    vars x,y;
    99 -> x;
    x =>

If you do it again and watch carefully you may be able to see that
command line will say 'DOING' while the lines are being processed, and
'DONE' when finished.

Now mark the next line and press CTRL-d:

    x * 5 =>

Do the same for each of these lines.

    [the cat on the mat] matches [??x on ??y] =>
    x =>
    y =>

The first line asks POP-11 to check that the list on the left matches
the "pattern" on the right. It does, so the result printed out is
<true>. The next two lines ask POP-11 to print out what X and Y were
matched against. (Don't worry too much about the details of the example
now.)


-- Run time errors -----------------------------------------------------

Now mark the following, and press CTRL-d.

    "two" + 3

The last line causes a "MISHAP" message to appear in the output file.
That was a "run time" error, i.e. in the attempt to actually run the
addition procedure, an inappropriate input was found. POP-11
cannot add words, only numbers. Don't worry about the details of the
mishap message for now.


-- Compile time errors -------------------------------------------------

Compiling a portion of a file means translating it into appropriate
instructions for the machine. We sometimes call this 'loading'. Errors
can also occur at compile time (load time).

Compile time errors are syntactic errors, where you've typed something
which is not 'grammatically' correct POP-11. Now mark the line below and
type CTRL-d  (or <ENTER> lmr) to see how syntactic error messages appear
on the command line, at the top of the window. The cursor will show you
how far the compiler had got before the error occurred.

    3 plus 4 =>

POP-11 does not recognize the word "plus" as an operator. Unless a word
or symbol is defined as an operator it cannot occur between two numbers
like that. For now, don't worry about the exact meaning of the error
message. You'll need to learn more about the syntax of POP-11 to
appreciate the details. NB as soon as you type something or move the
cursor, the message will disappear from the command line.


-- Looking back at the error message -----------------------------------

If you wish you can look back at the error message after it has
disappeared as follows:

Press the <ENTER> key to get the cursor onto the command line.

You can then press the Cursor-UP (CHARUP) key until you get the error
message back on the command line.

(The command line acts as a one-line window into a special file). This
should reveal the error message. If the error message is too long to fit
on the line, you can move the cursor right in the usual way to reveal
the missing bit.

To get the cursor back to the file you are working on, press the CHANGE
MODE key (sometimes indicated on keyboard maps as the SWITCHSTATUS or
STATUSSWITCH) to get the cursor back into this file. If you can't find
it, just press RETURN. VED will complain about the unknown command, but
don't worry.


-- Finding out what an error message means ----------------------------

(Skip this section on a first reading).
The error message may have a short code in it, e.g. MSEP, or MSW. This
means there is a help file with that name, explaining what the error was
about. You can look at it by typing

    <ENTER> help

then the code, then <RETURN>, e.g.

    <ENTER> help msep <RETURN>

If you wish try that now, then quit the MSEP help file with <ENTER> q,
to get back here.


-- Undeclared variables ------------------------------------------------

Try marking the following to see how undeclared variable messages appear
in the output file. Mark the next two lines and type CTRL-d:

    99 -> xxx;
    fido -> dog;

The best way to avoid warnings, is to make sure you declare all the
variables you need, thus:

    vars kitty, cat;        ;;; declare "kitty" and "cat" as variables.
    tom -> kitty;
    kitty -> cat;

You could try marking that range and loading it (CTRL-d or <ENTER>lmr).
You will see that there is no declaring variable message for kitty, or
for cat, since those were declared. But there will be a message for tom.


-- You can give commands in the output file too -----------------------

Note that the output file is just an ordinary file, and you can switch
to it using:

    <ENTER> ved output

to make any changes. You can save the output in a permanent disk file,
with <ENTER> w, or else have it forgotten with <ENTER> q.

You can also type a command in it and have it obeyed. Try typing
something like the following into your file called output, then mark and
load it:

    8888 + 2222 =>

Try typing variants of that into your output file after giving the
command
    <ENTER> ved output

then mark and load what you have typed.


-- USE <ENTER> w FROM TIME TO TIME -------------------------------------

The load marked range command (CTRL-d or <ENTER> lmr) loads a portion
of the file into temporary memory in the machine. However, you should
ensure that from time to time you save your work by "writing" your files
onto the magneting disc, the permanent memory attached to the computer.
you can tell VED to do this by giving the command

    <ENTER> w

Try it. It should write your 'output' file, or any other of your private
files that you have recently changed, and tell you that it is doing so.

Always try to remember to do
        <ENTER> w

occasionally as a precaution against losing work. (Actually, from
time to time VED's "autowrite" mechanism will write your files to disc
anyway. They will also be written when you leave POPLOG.)


-- Diverting output to a different file -------------------------------

You can divert output to a file called FRED by

    <ENTER> output fred

You can make output always go to the CURRENT file, whatever it is, by

    <ENTER> output .

However, this is generally rather confusing, unless you are an expert.
You can make output go onto the screen without going into your file by
means of the command

    <ENTER> output ^

E.g. try that command then mark and load the following line:

    9999 + 1 =>

After printing out the result, VED will say

    VED HERE: PRESS RETURN TO CONTINUE:

You can then press the RETURN key to get back into VED. To restore
printing into your output file, do

    <ENTER> output output


-- Related documentation ----------------------------------------------

See also
TEACH * VED     - using the editor to create text files of your own
TEACH * MARK    - marking a range
TEACH * VEDPOP  - using the editor to create programs

HELP *  MARK (Probably too detailed for beginners)

--- C.all/teach/lmr -------------------------------------------------------
--- Copyright University of Sussex 1989. All rights reserved. ----------