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.
setenv term vt100
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:
setenv DISPLAY mymachine
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.
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:
Note that most of the file options use a "File Tool" which allows you to select the file to operate on interactively. This looks a bit complicated, but you can always type the name of the file you want in the Selection: slot, and hit the "Edit" button.
You can also select a "range" of text. To do this, hold down the control key (ctrl) and use left mouse button to select a number of lines of text. The selected range is indicated by a black line that appears down the left of your screen.
A Search function is also provided.
Additional help with editing is found under the "287" menu. This online material is found in the directory $popPOP2000.
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
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:
Definition pi = 3.14159 End;
Grammatical constructs are specified using a bold version of the typewriter font. For example, we specify one form of the POP2000 define statement by
Definition variable = expression End;
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:
Definition pi = 3.14159 End;is an instance of the grammatical form
Definition variable = expression End;
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.
integers: These are of arbitrary precision that is they are only limited in size by the total amount of memory you have!
rationals: POP2000 can and will compute with fractions. If you divide one integer by another you will get a rational. You should usually avoid rational computations, unless you are doing symbolic algebra!
reals: These are represented by floating point numbers.
booleans: These are the values of the constants false and true.
23 is an integer 3.4 is a real 3/4 is a rational
A POP2000 variable is either
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).
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
Definition variable = expression End;
For example:
Definition pi= 3.14159 End;
binds the variable pi to have the value 3.14159
expr expr1 expr2 ...exprn expr1 + expr2 expr1 - expr2 expr1 * expr2 expr1 / expr2Every combination is understood to be a function applied to an argument or arguments [see note on the Lambda calculus]. In the case of the form
expr expr1 expr2 ...exprnThe expression expr is the function while expr1 expr2 ...exprn are the arguments.
In the case of the forms:
expr1 + expr2 expr1 - expr2 expr1 * expr2 expr1 / expr2the operators + - * / are the functions, each with two arguments expr1, expr2.
(expr1)This parenthesised form is used to resolve ambiguity. For example 2*3+4 could mean (2*3)+4 or 2*(3+4). In the absence of parentheses, an operator precedence and associativity rule is used by the POP2000 compiler. This treats multiplication as more binding than addition, so that 2*3+4 is interpreted as 2*3+4. All operators are less binding than direct function application, so that sin x + y is interpreted as (sin x) + y, that is apply the function sin to the variable x and then add the result to the variable y. The arithmetical operators are left associated, so that, for example, x-y-z means (x-y)-z and not x - (y-z). This, of course, is consistent with normal mathematical usage.
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
7
5 - 4
means "the result of subtracting 4 from 5".
A more complicated example is:
3+(4*5)
Here we evaluate 4*5 to get 20, and then add 3 to get 23.
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]
A POP2000 function is specified by the syntax
\ formals. body
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
(\x. x*x)
is the function which squares its argument. So
( (\x. x*x) 3)
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
( (\x. x*x) 7)
Strip and substitute for corresponding formals (x=7) :
7*7
Evaluate body
49
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
Definition square = \x. x*x End;
POP2000 responds:
<Compiled function: square>
and now we can use it
square 4;
POP2000 responds:
16
An example of a lambda expression with more than one argument is
\ x y. x + 2*y
And an example of its use is:
(\ x y. x + 2*y) (4 + 3) 5;
Evaluate the arguments
(\ x y. x + 2*y) 7 5)
Strip and substitute, x=7, y=5:
7 + 2*5
and evaluate
7+10
17
This is accessed by hitting the "Debugger" button on the POP2000 Control Panel. It is operated by a panel which contains the following buttons:
The function application (load `file`) will load any file as POP2000 program.
(+ 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.
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.
A note on the Lambda Calculus