Page 216 - DCAP506_ARTIFICIAL_INTELLIGENCE
P. 216
Artificial Intelligence
Notes Self Assessment
Fill in the blanks:
13. The ...................... predicate provides an alternative path for a program when the current
path fails.
14. Backtracking allows Prolog to nd all ...................... solutions to a given query.
14.9 Lists
A list is an ordered sequence of zero or more terms that has the following characteristics:
It is written between square brackets and separated by commas.
Every nonempty list is divided into a head and tail using the pipe (|) symbol. The tail of
a list is always a list and the head of a list is an element.
An empty list is written as [] and does not have a term.
The size of the list is not declared and can be increased or decreased dynamically within the
program.
Each element in the list is accompanied by a pointer, which indicates the location of the next
element in the list.
Example: Some examples of list are [jack, jill, jim], [1,2,3,5], [(a, sublist, in, list), main,
list], and [a|[b,c,d]].
Self Assessment
Fill in the blanks:
15. A ...................... is an ordered sequence of zero or more terms.
16. Each element in the list is accompanied by a ......................, which indicates the location of
the next element in the list.
14.10 Input/Output and Streams
Two groups of input/output predicates are obtainable for input and output: that is, those which
refer completely to a current stream, and those which need the stream to be explicitly specified.
Current Streams
There is one current input stream, one current output stream and one current error stream at any
specified time. At system startup these are the typical streams. If necessary, you can alter this
default setting. You should redefine a current stream only if you desire to consequently use it
frequently for input or output. The input/output predicates in this group implicitly address the
current streams, because a stream is not explicitly specified.
Explicitly Specified Stream
The specified stream must already be present when the equivalent predicate is called. If the
stream is a file, it must be open for reading or writing.
210 LOVELY PROFESSIONAL UNIVERSITY