Assignment 5. CS330 Programming Languages, Summer 2005 (Due Monday
July 28)
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
Some example code can be found here:
prologExamples.tar
Type gprolog and at the prompt you can load
the facts/rules by typing
['append.p'].
Then you are ready to issue queries. Remember the distinction between
variables (capital letters)
and relations,
List stuff in Prolog (3 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.
Define a relation drop such
that if drop(L1, N, L2) is true L2 is obtained
by dropping every Nth element from L1. For example:
drop([1,2,3,4,5,6], 2, [1,3,5]) is true.
(hint: define a relation dropaux(L1, N, L2, K) where L2 is obtained
from L1 by first copying K-1 elements
and then dropping an element and, from then on, dropping
every N'th element. Use dropaux
to define drop)
(hint to evaluate you have to use the is keyword: for
example K1 is K -1 if K is 5 then K1 will become 4)
Exploring Programming Languages (4pts)
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).
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.