Subversion Repositories programming

Rev

Blame | Last modification | View Log | RSS feed

irasnyd@duallie prolog $ cat natsq.pl
% Written By: Ira Snyder
% Due Date:   03-09-2005
% Homework #: 15 (Exercise #23)

nat(0).
nat(X) :- nat(Y), X is Y+1.

natsq(X) :- nat(Y), X is Y*Y.

irasnyd@duallie prolog $ pl
Welcome to SWI-Prolog (Multi-threaded, Version 5.1.13)
Copyright (c) 1990-2003 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- [natsq].
% natsq compiled 0.00 sec, 1,096 bytes

Yes
?- natsq(X).

X = 0 ;

X = 1 ;

X = 4 ;

X = 9 ;

X = 16 ;

X = 25 ;

X = 36 ;

X = 49 ;

X = 64 ;

X = 81

Yes
?-
% halt
irasnyd@duallie prolog $