More Prolog




CS152

Chris Pollett

Nov 29, 2021

Outline

Introduction

Queries With Multiple Variables

Lists in Prolog

findall

Quiz

Which of the following statements is true?

  1. We define a function to be strict if it is undefined (fails to terminate, or encounters an error) when any of its arguments is undefined.
  2. The following clause is a Horn clause:
    a1 ∧ a2 ∧ ... an → b1 ∨ b2
    
  3. Functions and special forms are the same thing in Scheme.

Built-in Predicates

is Predicate and Arithmetic Expressions

Strings in Prolog

I/O Predicates

display(X) -
    Prints X to the current output device (usually screen which is called userout).
nl -
    Write a newline to the current output device.
put(X) -
    prints a character X given as an ASCII integer to the current output device.
tab(X) -
    Insert X spaces on current line of current output device.
write(X) -
    Prints X to the current output device. Write pays attention to whether or not an operator 
    should be in infix notation, display ignores this information.
get(X) -
    gets the next ASCII character of value >32 from the current input device. 
    (On Unix systems have to  watch out since buffering goes on even when input
    device is the keyboard.)
get0(X) -
    get next character from current input device.
read(X) -
    reads a term followed by a period from current input device. the variable X is bound only 
    to the term and not the period
skip(X) -
    skip over X many characters from input device.
see(X) -
    set the file X to be the current input device. X=userin is the keyboard. I.e, see
    sets current input device to X.
seeing(X) -
    if X is a variable then X instantiated to name of current input device.
seen -
    close file return current input device to keyboard.
tell(X) -
    set the current output device to be the file X. The screen is the output device userout.
telling(X) -
    if X is a variable then X instantiated to name of current output device.
told -
    close file return current output device to screen. 

Debugging Predicates

trace -
    Put Prolog in mode where each step of Prolog search printed out. 
notrace -
    Takes Prolog out of trace mode.
spy P -
    Put a spy point on a predicate P. For example | ?- spy dog/2. would put a spy point on the 2-ary predicate dog. 
nospy P -
    Removes a spy point from a predicate P.
debugging -
    turns on debugging mode so that whenever spied-on predicates are called their information is displayed. 
nodebug -
    turn off debugging mode. 

Meta Predicates

Cut

Using Cut To Prevent Resatisfaction