Assignment 5. CS330 Programming Languages, Summer 2007
PLEASE READ CAREFULLY
MISSING DETAILS MAY COST YOU
Details
You might be interviewed regarding your submission.
Make sure you have written everything you
submit. For any function you are trying to write, you can request
what is the desired output for a particular input by email.
Late assignment policy: If the assignment is submitted
within three days from when it was due, you will get half the grade you
would get if you had submitted on time. You will not be able
to submit after three days. (exceptions to this rule only
if you have a VERY important reason).
IMPORTANT: The careful design
and documentation (i.e comments) of
your code will be important factors in your grade. If there is a bug
it's better to report it than hide it. Be honest, precise and clear and
you shall be rewarded. NEVER (at least in this class) sacrifice
clarity for efficiency of execution.
(10% of final grade - 10 points)
Astronomy in Prolog (3 points)
An astronomer provides you with the following information about
celestial objects in English:
Sun, sirius and betelgeuse are stars.
Mercury, venus, earth, and mars orbitthe
sun.
Moon orbits the earth.
Phobos and deimos orbit mars.
A planet is a celestial object that orbits the sun.
A satellite is a celestial object that orbits a planet.
A celestial object is part of the solar system if it is the sun, or a
planet or a satellite of a planet.
Encode these facts in Prolog building a system that can answer queries
about celestial objects.
Some examples that you will need to support are:
orbits(mars, sun) ?
(yes)
orbits(moon, sun) ? (no)
orbits(phobos, B) ? (mars)
orbits(B, mars) ?
(phobos and deimos)
planet(mars) ?
(yes)
planet(P) ?
(mercury, venus, earth)
satellite(phobos ) ?
(yes)
satellite(S) ?
(moon, phobos, deimos)
solar(sun) ?
(yes)
solar(sirius) ?
(no)
solar(B)
? ( sun, mercury, venus, earth, mars,
moon, phobos, deimos)
To run prolog, type in your rules and facts in a file with extension
.pl
Type gprolog and at the prompt you can load
the facts/rules by typing
['foo.pl'].
Then you are ready to issue queries. Remember the distinction between
variables (capital letters)
and relations.
List stuff in Prolog (2 points)
As we showed in class, a definition of the relation member for lists in
Prolog is the following:
mymember(X, [X|T]).
mymember(X, [Y|T]) :- mymember(X,T)
Define a relation multiple that is the property of
being a list with multiple
occurances of some element. (hint: use mymember) For example:
multiple([1,2,3]) is false and multiple([1,2,2,3]) is true.
Define a relation last such
that last(X,L) is true if X is the last element of list L.
For example last(1,[1,2,3]) is flase and last(3,[1,2,3]) is true.
Exploring Programming Languages (5pts)
Find a non-standard programming language and write
a 1 page (3-4 paragraphs) description of it. Provide
a small source code example that illustrates the strengths/
unique characteristics of your chosen language (this can
be taken directly from the web or other resources).
Obtain a compiler for the language and write a small program
in it (anything slightly more complicated than Hello World
will work). The example should also illustrate at least
one of the following concepts we have learned in
the class:
- class template
- constructor
- dynamic lookup
- dynamic or static type checking
- higher-order function
- overloading (ad-hoc polymorphism)
- parametric polymorphism
- subtyping
- inheritance
- tail recursion
- type inference
You delivarables will be a single pdf or doc file with
the following sections:
0) description
1) small example
2) your own example
3) your experience writing the program and making
the language work
Standard programming languages that can NOT
be used include: Java, C++, C, Perl, Visual Basic, Assembly.
If in doubt whether your choice is applicable send me an email.
Use of the web is encouraged.