Lecture 2: An Introduction to the POP2000 Language


The UMASS POP2000 System

**** THIS SYSTEM IS NOT INSTALLED IN THE EDLAB ****

How to start up UMASS POP2000.
Editing Files and Running POP2000 Code.
Changing your default font for VED under X.

The POP2000 Language

Typographic conventions used in these notes
Simple values in POP2000.
Variables in POP2000.
Definition variable = expr End; creates a new variable and gives it a value
Expressions in POP2000.
So what are functions in POP2000?.
An expression \(v1..vn) expr) denotes a function .
The Debugger.
The function load loads a file of POP2000 code.
The lambda calculus.

How to start up UMASS POP2000.

To start up UMASS POP2000 type POP2000 as a Unix command. You will get a message like this:

  Sussex Poplog (Version 14.5 Tue Feb 22 15:01:28 WET 1994)
  UMASS POP2000 (Version 1.0)
  initialising X windows

  Sussex XVed (Version 2.0 (motif), SCHEME Tue Sep 12 12:14:16 EDT 1995)
  X Server: MIT X Consortium
  initialising X windows

[Note for experts: getting UMASS POP2000 depends on an alias in the class .cshrc file, which itself depends on your own ~/.cshrc file. If you change this file, you may find yourself running a version MIT POP2000 which does NOT accord with the IEEE standard required for this class.

UMASS POP2000 is implemented under the Sussex Poplog system developed at Sussex University (Falmer UK), and employs the X-window system developed at MIT (Cambridge MA). ]

If you are logged in in the EDLAB, you will get a version which is customised for running under X-windows. In this version, you will be able to edit and test programs entirely within UMASS POP2000 system if you wish.

If you are logged in remotely, for example from home, and do not have an X-server on your local machine, you will get a version of UMASS POP2000 which is customised for running under a terminal emulator. If your emulator matches a VT100 terminal, this should be OK, but you may need to set the term environment variable before you run your POP2000. If POP2000 is unhappy with your terminal it will say so.

If you are logged in remotely from a machine which is running an X-server, for example another workstation in UMASS, or your own machine running an X-server using the ppp protocol, you should do:

where mymachine is the net-address of the machine you are logged in on. This will allow UMASS POP2000 to open windows on your machine.

Editing Files and Running POP2000 Code.

Under X-windows, a small "control panel" will pop-up when you start POP2000. This has a box labelled "File:". This contains the name of a default file ("unnamed.lam") that you can edit using the built-in VED editor. If you want to change this, put the mouse in the box, drag the mouse along the length of the name - it will now reverse its colours. Then type in the name of the file you want to edit, and hit the Do Edit button. After a brief pause a new window will appear with your file (possibly empty) in it.

If it is a file to contain text in the POP2000 language, the name should end with ".lam".

There is also "Exit" button to kill the POP2000 system.

Each edit window contains a "menu-bar" across the top. This is used in a style akin to that of the Macintosh. Currently this has the following menus attached:

Additional help with editing is found under the "287" menu. This online material is found in the directory $popPOP2000.

Changing your default font for VED under X.

If you want to use a different font, add a line of the form XVed*font: to your .Xdefaults file. You can obtain a (long) listing of available fonts by doing xlsfonts as a Unix command.
XVed*font: 7x12  # The default size - rather small for some.
XVed*font: 9x15  # A bigger size, which you may like better.

You can also change the font of a particular window by doing

Where font is the name of a font.

The POP2000 Language

Typographic conventions used in these Lectures

All expressions and other constructs of the POP2000 language which occur in these lectures are set in a typewriter font, An example of typewriter font is: Definition pi = 3.14159 End; .

Typewriter fonts are characterised by being fixed-width (every letter occupies the same amount of space on the page). In the HTML browser which has been constructed to let you view these lectures from within UMASS POP2000, POP2000 expressions will appear in red, since the VED editor always uses a single fixed-width font and provides no means of distinguishing text by using a different font, only by making variants on a given font.

Where it is important to make an expression of the language stand out, it will be placed indented as a line or lines of text separated from the English commentary. For example:

Grammatical constructs are specified using a bold version of the typewriter font. For example, we specify one form of the POP2000 define statement by

Here, because variable is in a bold font it means that you can write any POP2000 variable in place of it; likewise because expression is in a bold font it means that you can write any POP2000 expression in place of it. So, the previous statement:

is an instance of the grammatical form

Simple values in POP2000

POP2000 operates on the usual simple data-objects, that is to say data-objects that can best be thought of as having no internal structure.

23   is an integer
3.4  is a real
3/4  is a rational

Variables in POP2000

A POP2000 variable is either

A variable is terminated by white space or one of a number of separating characters, of which parentheses (, ) are the most important. Certain reserved-words cannot be used as identifiers.

For example the following are variables:


        x y x_23 +  ->

Warning - POP2000 gives some variables initial values, for example +, *, / . It is not a good idea to use these variables for your own purposes (except as variables local to a function).

Definition creates a new variable, gives it a value

Variables usually have values. We say that a variable is bound to a value when it is associated with the value. POP2000 has a statement which creates a new variable and binds it to the value of an expression

For example:

binds the variable pi to have the value 3.14159

Expressions in POP2000

Where the "action" takes place in POP2000 is in the evaluation of expressions. POP2000 expressions can have a number of syntactic forms, [in distinction to the Scheme language] which we will introduce gradually during the course of these lectures.

     3+4

is an expression, whose function is '+' and whose arguments are 3 and 4.

When POP2000 evaluates an expression of this form, it evaluates the function and arguments, and then applies the function to the arguments. Evaluating the above expression we get

Likewise:

means "the result of subtracting 4 from 5".

A more complicated example is:

Here we evaluate 4*5 to get 20, and then add 3 to get 23.

So what are functions in POP2000?

Well, actually functions are pieces of machine code (in effect subroutines for those who have taken CMPSCI 201). So the value of the variable '+' is a piece of code for doing addition.

[Note you can actually redefine POP2000 standard functions. This is NOT recommended for novices, for you may lose important capabilities]

Making your very own function

A POP2000 function is specified by the syntax

here formals a sequence of variables, and body is an expression. The entire construct is itself an expression. The particular syntax has been chosen to correspond as closely as possible with the Lambda Calculus notation of Church, who used the Greek letter "lambda", which, alas, is not available in the standard fonts used for computer programs.

Note that this is not an application of the function lambda, but is what is called a "special form" in POP2000.

For example

is the function which squares its argument. So

evaluates to 9.

The rule for evaluation of a lambda-function applied to arguments is to (a) evaluate all the arguments, and (b) strip off the 'lambda' and substitute the values of each argument for the corresponding formals, (c) evaluate the body of the lambda with the values substituted.



   ( (\x.  x*x) 3+4)

Evaluate the argument

Strip and substitute for corresponding formals (x=7) :

Evaluate body

This may seem a funny way of defining functions - in Pascal we would give the corresponding function a name, like "square". In POP2000, this is easily done

POP2000 responds:

and now we can use it

POP2000 responds:

An example of a lambda expression with more than one argument is

And an example of its use is:

Evaluate the arguments

Strip and substitute, x=7, y=5:

and evaluate

The Debugger

This is accessed by hitting the "Debugger" button on the POP2000 Control Panel. It is operated by a panel which contains the following buttons:

Generate Debug Code:
This is normally true, so that POP2000 generates code for the debugger by default. Turn it off to create smaller, faster programs.
Stop at All Breakpoints:
This is normally false. When set true, POP2000 will stop after it evaluates every compound expression such as (+ x 2). It will print out "frames" for the top n functions you are currently executing, where n is set by the "Number of Frames" slider.
Number of Frames:
This slider determines how many function-frames you will see.
Go To Next Breakpoint:
Execution continues until the next (automatically generated) breakpoint. Breakpoints occur after an expression has been evaluated.
Skip Current Function:
The execution of the current function will be completed without stopping at any breakpoints.
Help:
Prints out help information about the debugger.

The function load loads a file of POP2000 code.

The function application (load `file`) will load any file as POP2000 program.


A comparision with the Scheme Language

Functional languages can all be regarded as descendents of John McCarthy's LISP language. In the direct descendents of LISP, of which Scheme is the closest to POP2000, it has been conventional to employ a simple uniform syntax, in which compound expressions are written with the function followed by the arguments, all being enclosed in parentheses. For example:
    (+ 3 (* 4 5))

is a Scheme expression equivalent to 3+4*5 in POP2000. This syntax stresses the conceptual uniformity of functional languages, but at the price of making code have a form that is unfamiliar to users.

A note on the Lambda Calculus

In the lambda-calculus, which provides the theoretical underpinning of the POP2000 language, a function only has one argument. Thus (+ 2 3) is construed as ((+ 2) 3), where (+ 2) is the function "add 2". POP2000 does in fact support this model of computation (in distinction to Scheme which does not directly) but for beginners it is easier to think of a function such as + taking two arguments.