Show Menu
Cheatography

Prolog Cheatsheet Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

List Prolog

Empty List []
Car and Cdr [X|L]
string are list, "­hel­lo" stands for [104, 101, 108, 108, 111]
atoms are symbols 'anatom'
 

Higher­-order and meta predicates

Call, which is used to perform a query in a program call(G1, A1, A2, ...) adds arguments A1, A2, ... to goal G1 and performs the resulting query
e.g.

?- call(p­lus(1), 2, X).
X = 3. % i.e. plus(1­,2,X).

 

Numerical Expression

pow(_,­0,1).
pow(X,­1,X).
pow(X,N,R) :- N1 is N-1, pow(X,­N1,R1), R is X*R1.