Lab 4
(i) Preparation for Lab 4
GNU Prolog is installed on tux.cs.drexel.edu. You can run it by
typing prolog.
You can also download and install Prolog on your computer from
http://www.gprolog.org/.
To load a file from the current directory, enter "[filename]." If the filename is .pl, you can leave off the file extension. For example, to load last.pl you would enter "[last].". The period after the file name is required.
GNU Prolog
1.3.0
By Daniel Diaz
Copyright (C) 1999-2007 Daniel Diaz
| ?- [last].
compiling /home/mwb33/public_html/cs360_2013/lab4/last.pl for byte code...
/home/mwb33/public_html/cs360_2013/lab4/last.pl:1: warning: singleton variables [X] for last1/2
/home/mwb33/public_html/cs360_2013/lab4/last.pl compiled, 0 lines read - 665 bytes written, 16 ms
yes
To quit prolog type Ctrl-D (end
of file) or type "halt.".
1. Run (on tux) and analyze all examples of Prolog code of the document Mark’s Intro to Prolog.
2. Prepare the following Prolog code.
1. Create a min function
that finds the minimum element in a list, i.e. min(X,L) is true when X is the
minimum element of the list L.
Example:
| ?- min(10,[1,2,3,4,5]).
no
| ?- min(1,[1,2,3]).
true ?
yes
| ?- min(X,[2,5,1,4,2]).
X = 1 ?
2. Create a sentence
function in Prolog, i.e. sentence(L) is true when the list L contains a valid
sentence. For this problem, a valid sentence will be defined as follows.
Sentence -> noun_phrase verb_phrase
noun_phrase -> article noun
verb_phrase -> verb noun_phrase
Nouns -> boy, girl, dog, cat
Verbs -> sees, pets
Articles -> a, the
Examples:
| ?- sentence([the,boy,pets,a,dog]).
yes
| ?- sentence([the,girl,sees,a,cat]).
yes
| ?- sentence([girl,pets,boy]).
No
3. Run, test (both done on tux) and analyze Prolog and Scheme code provided in the file Lab 4 code. Review SICP sec. 4.4.1 prior to running the scheme query language.