Logic programming


next up previous contents
Next: The trend to declarative languages
Up: No Title
Previous: List processing and Lisp
Back: to main list of student notes

Logic programming

The idea that one expresses a program in logic. The most familiar logic programming language is Prolog - see my notes for the expert systems lecture. Here's an example (somewhat simplified, so not quite correct Prolog). Lisp is one of the two main AI languages; Prolog is the other. In this example, :- means ``if'' and , means ``and''.

replace(Board,NewBoard) :-
    at(Board,From,Piece), is(Piece,pawn),
        %  if there's a pawn at From
    at(Board,To,_),
        %  and any piece at To
    one_diagonal_ahead(From,To),
        %  one diagonal forward
    copy(Board,NewBoard),
        %  then the new state of the board is like Board
    make_empty(NewBoard,From),
        %  but with From empty
    move(NewBoard,Piece,From,To).
        %  and the pawn at To.


next up previous contents
Next: The trend to declarative languages
Up: No Title
Previous: List processing and Lisp
Back: to main list of student notes



Jocelyn Ireson-Paine
Wed Feb 14 23:46:11 GMT 1996