Documente Academic
Documente Profesional
Documente Cultură
Introduction
This week in ITECH5403 we're going to have our first hands-on section – where you'll learn the basics of
functional programming using the LISP programming language.
After you've completed either the LISP exercises – even if that's after the lab has finished – complete the
review questions as homework. As discussed previously, these questions are the EXACT questions which
will make up 80% of your exam – so it'll pay to know the answers to them! Also, you'll need to understand the
concepts and principals involved for later lectures because we're going to be building on our knowledge as we
go!
Remember – when you do go about answering the question, you aren't expected to know every single answer
from memory – sometimes it's best to do a little research / reading / re-reading of materials and come up with
a great, and correct, answer rather than just 'taking a stab' at the question and hoping you're right!
Also, remember that it's not a race! The person who wins is not the person who rushes through & completes
the exercises the fastest – it's the person who understands the material the best!
Installation is as simple as running the installer and clicking [Next] | [Next] | [Close] at which point you'll have
a GNU CLISP 2.49 shortcut (or similar if the version number changes) on your desktop which can be
launched:
You might actually find it rather cool and quite fun – functional programming is waaayy different to the
imperative languages! =D
Review Questions
1. Why was the slowness of interpretation of programs acceptable in the 1950's? And why in recent
years has it become largely acceptable to use purely-interpreted languages again? [Q5, PS-Q22]
In the 1950s, processors did not have floating-point data types which were implemented in hardware! Instead, all floating
point operations had to be performed in software – which was very slow. Because of this, the computational overhead of
the interpreter was relatively insignificant!
On modern PCs, processors are so fast that we rarely need to write code which is incredibly optimised and fast – because
even inefficient code will be executed incredibly quickly.
BASIC (Beginners All-purpose Symbolic Instruction Code) was important in the early 1980s because it was designed so
that beginners could learn to program in a relatively simple and straight-forward manner. The BASIC language allowed
interpreters to be created which were small in size and could be added to home computers of the day (which had very
limited resources), so people could learn to code on their computer, not require access to a terminal with a single central
large / expensive computer at a business or institution.
Coupled with the language design which made it friendly to work with (it emphasised programmer time over computer
time), it lead to a large increase in the number of programmers working in the I.T. field.
A nonprocedural language is one where not every single instruction and the order in which it is to be carried out is
explicitly stated. Instead, facts / data are provided, along with a number of rules with which to interpret and operate on
this data are provided. When a task is to be completed in a nonprocedural language, the computer applies the rules to the
facts / data in order to provide a solution or answer.
4. What three concepts are the basis for object-oriented programming? Provide a brief explanation or
example of each concept. [Q42]
The three concepts which are the basis for object-oriented programming are:
- Abstraction – where users are free to create their own custom data structures to fit a problem,
- Encapsulation – where data is hidden / protected from misuse or abuse (this also helps to simplify access to the
data, because it can be tightly controlled with regard to who can access it and what they can do to the data), and
- Polymorphism – where data types can act in a similar or different way depending on the data type – in essence,
this allows us to "program to an interface", so we might have a Door class and a BankAccount class, both of
which might support an "Openable" interface whereby they have an open() method. If we then write another
5. What is the primary application area for which Ada was designed? [Q38]
Ada was designed as the primary programming language to be used in US military applications, with the goal code
developed being able to be shared across multiple projects, thus decreasing development time and cost.
6. Describe the characteristics of a logic programming language such as Prolog. What types of
processing is it best used for? Give an example of a simple Prolog program.
Programs in logic programming languages do not state exactly how a result is to be computed - instead, they describe the
necessary form and/or characteristics of the result (i.e. the facts and rules which can be used to derive the result).
Prolog programs consist of collections of statements - and while Prolog has only a few kinds of statements, they can
quickly become rather complex. One common use of Prolog is to create a kind of 'intelligent database' – for example we
could say:
Once these facts have been established, we can create a rule to query our facts like this:
grandparent(Shmi, Luke).
Problem Set
1. Make an educated guess as to the most common syntax error in LISP programs [PS7]
Because of the simple syntax of LISP, few syntax errors occur in LISP programs. Unmatched parentheses is the
most common mistake.
2. LISP began as a pure functional language but gradually acquired more and more imperative features.
Why? [PS8]
3. Describe, in your own words, the concept of orthogonality in programming language design. [PS12]
Orthogonality in a programming language means that a relatively small set of primitive constructs can be combined in a
relatively small number of ways to build the control and data structures of the language.
If a language has a high degree of orthogonality, then all of its primitives (integers, floats, chars, booleans, etc.) can be
used with each other.
A lack of orthogonality in a language leads to exceptions to the rules of the language, i.e. this primitive can be used with
these other primitives except that one, and these types (arrays, pointers etc.) except that type.
Orthogonality is closely related to simplicity, where the more orthogonal the design of a language, the few exceptions the
language rules require… however, too much orthogonality can also cause problems, as it allows for extremely complex
constructs - in effect, it allows for combinational explosion, which means that because every primitive/type can work
with every other primitive/type the number of combinations can get very large, which makes the code harder to
read/understand/work with.
[This is an example only – accept any answer which makes valid points about orthogonality.]
4. What are the arguments both for and against the idea of a typeless language? [PS14]
The argument for typeless languages is their great flexibility for the programmer. Literally any storage location can be
used to store any type value at any time. This is useful for very low-level languages used for systems programming. The
drawback is that type checking is impossible, so that it is entirely the programmer's responsibility to ensure that
expressions and assignments are correct – for example, that you are not trying to multiply a numeric value by a string or
other such nonsensical operation.
5. Explain two reasons why pure interpretation is an acceptable implementation method for several
recent scripting languages. [PS15]
Firstly, it's simpler and therefore easier to write an interpreter than to write a compiler and associated toolchain (pre-
processor, linker etc.). Secondly, modern processors are very fast and programs tend to rarely be CPU-limited, so the
overhead in the live interpretation of program code into machine code is a relatively small percentage of the overall
processing requirements – and the interpretation itself can happen at a very fast rate.
6. Why, in your opinion, do new scripting languages appear more frequently than new compiled
languages? [PS24]