Subversion Repositories programming

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
107 ira 1
irasnyd@duallie prolog $ cat natsq.pl
2
% Written By: Ira Snyder
3
% Due Date:   03-09-2005
4
% Homework #: 15 (Exercise #23)
5
 
6
nat(0).
7
nat(X) :- nat(Y), X is Y+1.
8
 
9
natsq(X) :- nat(Y), X is Y*Y.
10
 
11
irasnyd@duallie prolog $ pl
12
Welcome to SWI-Prolog (Multi-threaded, Version 5.1.13)
13
Copyright (c) 1990-2003 University of Amsterdam.
14
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
15
and you are welcome to redistribute it under certain conditions.
16
Please visit http://www.swi-prolog.org for details.
17
 
18
For help, use ?- help(Topic). or ?- apropos(Word).
19
 
20
?- [natsq].
21
% natsq compiled 0.00 sec, 1,096 bytes
22
 
23
Yes
24
?- natsq(X).
25
 
26
X = 0 ;
27
 
28
X = 1 ;
29
 
30
X = 4 ;
31
 
32
X = 9 ;
33
 
34
X = 16 ;
35
 
36
X = 25 ;
37
 
38
X = 36 ;
39
 
40
X = 49 ;
41
 
42
X = 64 ;
43
 
44
X = 81
45
 
46
Yes
47
?-
48
% halt
49
irasnyd@duallie prolog $
50