next up previous
Next: Programming with CLP() (II) Up: Adding Computation Domains: CLP Previous: Interacting with CLP() (II)

Programming with CLP($\Re$) (I)

  $\mbox{$\bullet$}$
The folowing simple, recursive program defines the natural numbers:
nat(0).
nat(N):- N > 0, nat(N-1).

(zero is a natural number, and a number greater than zero is also a natural number, provided that its predecessor is a natural number)
?- nat(X).
X = 0 ;
X = 1 ;
X = 2 ;
?- nat(3.4).
no
?- nat(-8).
no
  $\mbox{$\bullet$}$
The above definition can also be written as
nat(0).
nat(N + 1):- N >= 0, nat(N).

and works exactly in the same way



Last modification: Thu Oct 7 12:04:03 MEST 1999 <webmaster@clip.dia.fi.upm.es>