Search                        Top                                  Index
TEACH PROGLECT2                                    Aaron Sloman Oct 1998
Revised 25 Oct 2011


See also TEACH PROGLECT1

CONTENTS

 -- Some reminders from previous lecture(s)
 -- Learning what is possible: some simple examples
 -- Using an AI programming environment
 -- -- editor
 -- -- an AI language
 -- Pop-11
 -- Learning about Pop-11
 -- o The grammar (syntax) of the language:
 -- o The "internal semantics" of the language:
 -- o The "external semantics" of the program
 -- More on the internal semantics of Pop-11
 -- -- Pop-11 data types
 -- -- Pop11 control structures
 -- -- . Sequences of instructions
 -- -- . Conditional instructions
 -- -- . Multi-branch conditionals
 -- -- . Loops of various kinds
 -- -- . Packaging re-usable instructions into named procedures
 -- -- -- Procedures without parameters;
 -- -- -- Procedures with parameters (i.e. inputs, arguments)
 -- -- -- Procedures with inputs and outputs
 -- -- -- The general form: multiple inputs and outputs
 -- -- . Procedure calls with automatic "return" to caller
 -- -- . Various kinds of jumps and abnormal exits
 -- Using Pop-11 via VED
 -- -- Compiling from a VED buffer
 -- -- Menu-driven compilation
 -- -- Using VED to access information files
 -- -- Using VED to access library files
 -- -- Using ESC h and ESC n
 -- Libraries
 -- Learn to use the editor VED
 -- Other Pop-11 facilities
 -- . Reading more about these facilities:

-- Some reminders from previous lecture(s) ----------------------------

AI has two sorts of closely related high level goals

    AI as engineering

    AI as science

For both goals it is important to be able to build models that can be
tested

(a) to see if they work (i.e. if they have the claimed potential,
    to explain, or to do something useful)

(b.1) in the case of engineering:
      to see if they actually perform the useful tasks they are intended
      to perform (e.g. diagnosing illness, controlling chemical plant,
      teaching learners, etc.)

(b.2) in the case of science:
      to see if the model is correct, or at least fits the facts,
      or explains how animals and people actually work.

There are many methodological problems about how to test such models but
we ignore them for now.

This course is about how to produce models especially models that
involve complex symbol-manipulating capabilities.

For that you have to learn

    o what sorts of models are possible

    o how to specify them so that you can plan a design

    o how to actually write the code to implement the design

    o how to test and debug the system (it won't work first time!)

    o how to explain how your system works (i.e. write a report on it)


This involves developing a host of special skills and knowledge. The
main ones are:

    o Fluency with the editor. This takes much practice and a study
      of TEACH VEDNOTES to learn about the powers of the editor.

        - To read online documentation
        - To create files with program code, with your own documentation
        - To test and debug programs interactively
        - Possibly to send and receive email.

    o Learning the programming language we have chosen, Pop-11
    (This is a very powerful, flexible, extendable language,
    supporting many types of software development.)

    o Learning how to learn about the language and the editor.
    This means learning to find your way around the online
    documentation, the TEACH, HELP, REF files, and the online
    libraries, using SHOWLIB.

NB: The lectures CANNOT convey all the material.

So I shall present only high level overviews most of the time.
Students will have to supplement this by

    (a) reading
            The Pop-11 primer, TEACH POPCORE,
            many online teach files.

            Books on AI, e.g. Sharples, Franklin, Nilsson, Winston,
            Russell and Norvig, others.

    (b) developing insight and fluency by practising programming

Total time: preferably several hours a week.

-- Learning what is possible: some simple examples --------------------

Example 1

    pop11 +eliza

    If installed on your system.

Example 2
    pop11 +gblocks

    If installed on your system.

Example 3
    The riverworld

        lib river

        false -> popsyscall;    ;;; for me only

        putin(fox);

        getin();

        TEACH RIVER shows you how to specify a solution, then
        refine it, explaining some basic programming ideas
            (procedures, arguments(inputs), sequences)

Example 4
    Programs that plan and search, e.g.

        uses poprulebase

        uses prbriver

        prb_run(
            depth_first,
            [[goal
                [
                    [isat man left]
                    [isat grain right]
                    [isat fox right]] ] ]);

Example 5

    uses newkit
    teach sim_sheepdog.p

Example 6
    uses rclib
    uses ved_rcdemo
    ENTER rcdemo rc_neural
        shows a teach file illustrating how to implement a simple type
        of trainable neural net in pop11.



Note: this course does not teach neural net programming, or evolutionary
computation. However the basic skills provided can be used later on to
write programs of those sorts.


-- Using an AI programming environment --------------------------------

-- -- editor

o For writing code, documentation, browsing, running programs,
      debugging, sending and reading email (e.g. from tutor).

-- -- an AI language

o For specifying information of various kinds

    specific factual knowledge
        The chicken is at the left bank

    general factual knowledge
        A bank cannot be put in a boat
            Can be done in a declarative or a procedural format

    procedural knowledge (how to, algorithms)
        How to get an animal safely across the river

    architecture (how it is all put together)
        A collection of files compiled together in a certain
        order. An initialisation procedure which creates all the
        parts of the program and gets them ready to run.

    tracing and cosmetic output
        Trace printing may be very useful while testing or debugging
        or producing  evidence of what the program does.

The main AI languages are Lisp, Prolog, Pop-11 and various extensions,
e.g. rule-based systems such as OPS5 and its descendants (e.g. SOAR) and
various kinds of toolkits, e.g. the Birmingham SIM_AGENT toolkit.
In recent years sophisticated AI languages have also used "object
oriented" extensions, e.g. Objectclass in Pop-11 and CLOS in Common
lisp.

Some people use C and C++ for AI, because of speed and portability, or
they use Java for portability and easier development or greater
robustness than C or C++ (e.g. fewer memory leaks). However, using a
non-AI language can sometimes make development much harder than using
special purpose AI languages, e.g. because there's no automatic store
management, or because there's no facility for defining new syntactic
extensions, or because the compiler is not available at run time, or
because there is no built in pattern matcher and it is hard to implement
one, or ....

There is no best language. We use Pop-11 here not because it is claimed
to be best, but because we know it is suitable both for teaching
beginners and for doing advanced research, because it supports a wide
range of programming paradigms only subsets of which are usually found
in one language (apart from Lisp), because it has a lot of tried and
tested teaching materials for AI and cognitive science, and because we
know it well. Also, since 1999 it is free, despite previously being sold
as an expensive commercial product.

-- Pop-11 -------------------------------------------------------------

This is one of several AI languages with different properties.
Pop-11 is in many ways like Common Lisp, except that it has
a form of syntax which is more verbose and redundant, which
for many people (not all) makes it more readable, especially
beginners.

Use VED for the programmable editor, for accessing all the
Poplog online documentation, and for developing and testing
Pop-11 programs. XVed is the multi-window version of Ved.

VED itself is just a collection of Pop-11 subroutines in Poplog adding
up to a "hypertext" document browser, able to follow cross-links rapidly
(like Netscape without the pictures).
    (Also works for mail, net news, other things)

A partly similar editor is Emacs, widely used by computer scientists,
but not so well integrated with Pop-11.

-- Learning about Pop-11 ----------------------------------------------

In order to learn a programming language you have to learn several
different sorts of things, not necessarily in this order:

The grammar, the internal semantics, the external semantics (varies),
how to create programs, how to test and debug programs, how to
use the libraries and documentation, etc.

In more detail. This is what you have to learn.

-- o The grammar (syntax) of the language:

    What the lexical items are (e.g. symbols for words, strings,
        numerals....)

    How they can be put together to form larger programming units
        declarations, assignments, referring expressions,
        procedure definitions, etc. etc.

        This includes learning scoping rules (which bits of program
            can refer to others: global vs local variables)

    What the syntactic categories of the language are
        E.g. types of variables, types of complex expressions.
        (Experts can look at: REF popsyntax)

    How the syntactic categories can be extended
        (not possible in all languages)


-- o The "internal semantics" of the language:

    What sorts of entities are in the "virtual machine" when
        programs run.

    - Entities referred to explicitly: the data-types of the language
        both primitive (e.g. pairs) and derived (e.g. lists).

        e.g. numbers, words, strings, arrays, lists, databases, records,
             files, devices, editor buffers, windows...

    - Entities referred to implicitly: the components of the virtual
        machine architecture.

            In Pop-11 these include the dictionary, the heap,
            the user stack, the procedure stack, ....

            See the picture in the printed PRIMER, or the online
            primer
                http://www.cs.bham.ac.uk/research/poplog/primer/
                http://www.cs.bham.ac.uk/research/poplog/primer/popmodel.eps

            See TEACH STACK, after you have done TEACH RESPOND

    - The types of processes that can occur
        Compile time processes:
            analysing program, translating to machine code
            checking for syntactic errors
            compilng libraries

        Run time processes (when your programs are already compiled,
        and start running):

            invoking a procedure, returning from the procedure
            creating new items (lists, strings, etc.)
            assigning values to variables
            getting values of variables
            putting items on the stack
                (passing arguments, returning results)
            testing conditions
            looping
            discovering and reporting run-time errors
            garbage collection
            (and many more)

NOTE: Some processes (at compile time and at run time) occur because
your program explicitly specifies them. Others (e.g. garbage collection,
error checking) occur because the virtual machine does them under
certain conditions.


-- o The "external semantics" of the program

    This varies from program to program.

    E.g. the river program refers to the left and right side, the
    boat, the fox, the chicken, eating, etc.

    An office automation package may refer to people, salaries,
    ages, jobs, phone numbers, etc.

    A program controlling a chemical plant may refer to temperatures,
    flow velocities, pumps, switches, sensors, etc.

    A graphical program may refer to lines, circles, colours,
    menus, buttons, etc.

Getting to understand all these different aspects of syntax and
semantics and how they relate to one another takes a lot of time
and can often be confusing, because it is complicated.

See The Pop-11 Primer. (Also TEACH PRIMER)
Read the preface, chapter 1 and chapter 2.
(Skimming details on a first read.)

See TEACH POPCORE

-- More on the internal semantics of Pop-11 ----------------------------

-- -- Pop-11 data types

Pop-11 has many kinds of "data-structures" for storing
information:

E.g. information that is:

    provided by the user
        where the fox, chicken and grain start off

    created by the program
        new location of an animal or the boat, after the program
        has run for a while

    read in by the program while it is running, e.g. from
        other programs, sensors, etc.
        Example information about the user's question in Eliza.

    Types of data include
        numbers (various kinds), words, strings,
        lists, vectors, properties, and many more

Some data types are "primitive" whereas others are "derived", namely
built out of the primitive structures. E.g. in Pop-11 integers and
decimal numbers (reals) are primitive, whereas lists are derived.
They are built out of pairs.

    For this course a subset of data types will suffice.
    (See TEACH * POPCORE, and the section on data types in the PRIMER)

    (Experts see REF * DATA)


-- -- Pop11 control structures

To understand a programming language you need to know BOTH what
kinds of information items it can create and manipulate, and ALSO
how to build up processes which do the work you want.

This means assembling complex instructions from simple ones, using the
"control structures" provided by the language.

There are many sorts of "control structures", including the following.

-- -- . Sequences of instructions

    action1;
    action2;
    ......

-- -- . Conditional instructions

    if condition then action endif

-- -- . Multi-branch conditionals

    if condition1 then action1
    elseif condition2 then action2
    elseif ....
    else ...
    endif

-- -- . Loops of various kinds

    repeat <instruction sequence> endrepeat

    while <condition> do <action> endwhile

    until <condition> do <action> enduntil

Loops with "loop variables"

    for x from 1 to 75 do <action involving x> endfor

    for x in list do <action involving x> endfor


Loops involving the pop-11 database

    foreach <pattern> in <database> do <action> endforeach

    forevery <list of patterns> in <database> do <action> endforeach

... and several more. See HELP * LOOPS, HELP * CONTROL


-- -- . Packaging re-usable instructions into named procedures


-- -- -- Procedures without parameters;

Example from TEACH FACES

    ;;; A global declaration
    vars win1;

    define fixed_eyes();
        rc_new_window_object(600, 10, 400, 400, true, 'WIN1') -> win1;
        rc_draw_blob(0, 0, 70, 'red');
        rc_draw_blob(-35, 25, 15, 'blue');
        rc_draw_blob(35, 25, 15, 'blue');
    enddefine;


    /*
        ;;; test it

        fixed_eyes();   ;;; runs the procedure

    */


-- -- -- Procedures with parameters (i.e. inputs, arguments)

    ;;; Another example from TEACH FACES

    define located_eyes(x, y);
        ;;; draw the main circle for the face, centred at (x, y)
        rc_draw_blob(x, y, 70, 'red');

        ;;; draw the left eye, radius 15
        rc_draw_blob(x - 35, y + 25, 15, 'blue');

        ;;; draw the right eye, radius 15
        rc_draw_blob( x + 35, y + 25, 15, 'blue');
    enddefine;

Note how the parameters are used in the procedure body.

    /*
        ;;; test it

        located_eyes(-100, 100);   ;;; runs the procedure

        located_eyes(100, 100);

        located_eyes(100, -100);

    */


-- -- -- Procedures with inputs and outputs
    output locals, input locals


    define greeting(name) -> result;

        [Hi there ^name. How are you?] -> result

    enddefine;

Note how the value of name is used.

    /*
        ;;; test it, giving a WORD as input, printing the output

        greeting("fred") =>

        ;;; save the output in a variable
        vars list;
        greeting("suzy") -> list;

        ;;; now print it, twice

        list =>

        list =>

    */



-- -- -- The general form: multiple inputs and outputs

    define name(arg1, arg2 ...) -> (output1, output2...);

        actions

    enddefine;

Note: this is not an instruction to DO the instructions inside the
procedure definition, but an instruction to make available a re-usable
collection of instructions with a name.

        See TEACH DEFINE, HELP DEFINE, PRIMER chapter 4

-- -- . Procedure calls with automatic "return" to caller

    <action1>;

    do_stuff(x,y,z);    ;;; when do_stuff finishes it
                        ;;; automatically returns here

    <action2>;


A procedure call is an instruction to do something using previously
defined procedures.

Pop-11 uses the procedure call stack to remember which procedures are
currently active. When the do_stuff procedure has finished, it remembers
to come back to the procedure that was previously running, and continue
with <action2>

-- -- . Various kinds of jumps and abnormal exits

    goto <label> (not recommended)

    return()

    quitloop(N)

    exitto(procedure)

    exitfrom(procedure)

etc.

See HELP * CONTROL, for a wider range of control constructs provided in
POp-11.

Further kinds of control structures are involved in:

    error handling (See HELP * MISHAP),

    rule-based programming (e.g. see TEACH * RULEBASE)

    method invocation in object oriented programming
        (e.g. see TEACH * OOP).



-- Using Pop-11 via VED -----------------------------------------------

-- -- Compiling from a VED buffer

;;; make sure the RCLIB package is compiled
uses rclib;

;;; Create a window (then move it so that you can read this text)
;;; Declare a variable called win1 and give it a window
vars win1 =rc_new_window_object(600, 10, 400, 400, true, 'WIN1');

;;; define a procedure
define rc_square(side);
    repeat 4 times
        rc_draw(side);
        rc_turn(90);
    endrepeat
enddefine;

rc_square(50);
rc_square(100);

;;; do the same at a different part of the picture
rc_jumpto(-150, -150);
rc_square(50);
rc_square(100);

;;; Do the same after rotating through an angle of 45 degrees
rc_turn(45);
rc_square(50);
rc_square(100);

;;; Clear the picture
rc_clear_window_object(win1);
repeat 8 times
    rc_turn(45);
    rc_square(50);
    rc_square(100);
endrepeat;


vars colours =
    ['red' 'orange' 'yellow' 'green' 'blue' 'violet'
     'pink' 'brown' 'white' 'black'];

repeat 50 times
    ;;; Draw 50 blocks of random location, random size, using
    ;;; randomly selected colours;
    rc_draw_blob(
        random(850) - 350, random(300) - 150, 5 + random(100),
            oneof(colours));
endrepeat;

rc_kill_window_object(win1);

-- -- Menu-driven compilation

It is possible to do (nearly) everything from the keyboard.

However, for those who prefer menu-based interaction, try

    ENTER menu compiling
    ENTER menu xved
    ENTER menu mail
    ENTER menu

-- -- Using VED to access information files

About Pop-11
    TEACH * POPCORE

    HELP * lists
    HELP * define
    HELP * control
    HELP * for
    HELP * if
    HELP * MATCHES
    HELP * DATABASE


    REF * data
    REF * lists

    TEACH * PRIMER

About VED
    TEACH * usefulkeys
    TEACH * vedpop
    TEACH * vedproc
    TEACH * lmr

    HELP * mark
    HELP * vedsearch
    HELP * vedkeys
    HELP * vednotes
    HELP * XTERMKEYS

    REF * vedcomms
    REF * vedsearch

    HELP * XTERMKEYS


About Unix
    TEACH UNIX.INTRO
    HELP CTWM
    HELP * SHELL
    HELP * UNIX.COMMANDS

    MAN ls
    MAN chmod

and many many more.

-- -- Using VED to access library files

    LIB * river
    LIB * elizaprog
    LIB * ved_send

Many VED commands invoke autoloadable library files.


-- -- Using ESC h and ESC n

    ESC h  -- invokes the library access mechanisms on word to right
              using type specifier to left. (Hypertext in Ved)

    ESC n --  searchers for Next cross reference indicated by an
              asterisk: e.g. HELP * VEDGETSYSFILE
              (Was more useful before the Ved cursor could be moved
               using a mouse!)

-- Libraries ----------------------------------------------------------

Poplog, and the editor VED support several library mechanisms for code
and documentation.

Many libraries and sub-libraries
    (a) in Poplog system (for different languages)
    (b) local to site
    (c) shared between a group of users
    (d) individual

Different library categories (each can be in the above
sub-libraries):
    Utilities
        Programming utilities and extensions to VED
        "autoloadable" and "non-autoloadable"

    Demonstration programs

    Tutorial documentation

    Help and reference documentation

    Other information

All the libraries are accessible by VED

See HELP * LIBRARIES, REF * LIBRARY


-- Learn to use the editor VED ----------------------------------------

You can get most benefit from the Pop-11 development environment if you
are fluent at using the editor VED, which can communicate directly with
the incremental compiler for Pop-11 (in the very same process).

(This also works for the other Poplog languages, Lisp, Prolog, ML).

  Different styles of use:
    menus, function keys, commands, escape and control sequences.

    Single window vs multi-window

    See TEACH VEDNOTES handout, also TEACH * VEDNOTES online,
    and
        HELP * XTERMKEYS
        REF  * VEDCOMMS
        HELP * VEDSEARCH
        HELP * VEDKEYS
        HELP * LOGICAL_KEYS
        REF  * VEDPROCS

  Revision
    TEACH * RHYME
    TEACH * REVISE

-- Other Pop-11 facilities --------------------------------------------

Sophisticated store manager with automatic "garbage collection"

Interrupt and signal handling

Interface to the operating system and file system
    VED: ENTER unix <command>

External language interface (e.g. for C, Fortran)

Saved images, for storing pre-compiled programs.

A "lightweight process" mechanism (different concurrent processing
threads, or programs that use "saved states", types of simulations.
See HELP PROCESS).

An object oriented programming extension to Pop-11 (Objectclass)
See TEACH OOP

Graphical facilities, including mouse and keyboard event handling.
See TEACH RC_GRAPHIC
Various X interface development tools
See HELP RCLIB


-- . Reading more about these facilities:

Interrupt and signal handling See HELP * INTERRUPT, REF * ASYNC

Interface to the operating system and file system
    E.g.
        REF * SYSIO, REF * SYSUTIL, REF * SOCKETS
        REF * EXTERNAL
        REF * SYSTEM

In VED
        ENTER unix <unix command>
            e.g. ENTER unix who

External language interface (e.g. for C, Fortran)

Saved images, for storing pre-compiled programs.
    See HELP * SYSSAVE


An object oriented programming extension to Pop-11 (Objectclass)
    TEACH * OOP
    HELP * OBJECTCLASS

Graphical facilities, including mouse and keyboard event handling
    TEACH * FACES
    TEACH * GSTART
    HELP * rc_graphic  (relative coordinate graphics)

    TEACH * RCLIB_DEMO.P
    TEACH * RC_LINEPIC

    TEACH * VTURTLE (drawing in a VED buffer)

Various X interface development tools
    E.g.
        HELP * RC_CONTROL_PANEL

        TEACH * VED_MENU

    A motif-based package.
        TEACH * PROPSHEET
        REF   * PROPSHEET
        REF   * POP_UI




Continued in TEACH * PROGLECT3

--- $poplocal/local/teach/proglect2
--- Copyright University of Birmingham 2000. All rights reserved. ------