playground/prolog/hello.pl

62 lines
961 B
Prolog

/*
$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.2.4)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
?- [user].
|: nat(0).
|: nat(s(N)) :- nat(N).
|: ^D% user://1 compiled 0.01 sec, 2 clauses
true.
?- nat(0) -> true; abort.
true.
?- nat(s(s(s(0)))) -> true; abort.
true.
?- not(nat(s(s(z)))) -> true; abort.
true.
*/
/*
plus(X, 0, X).
plus(0, X, X).
plus(X, Y, Z) :- plus(s(X), y, s(Z)).
*/
/*
member(X, [X|_]).
member(X, [_|L]) :- member(X, L).
?- member(1,[1,2,3]) -> true; abort.
true.
?- not(member(4,[1,2,3])) -> true; abort.
true.
*/
/*
range(ST,EN,N) :- N>=ST, N=<EN.
?- not(range(1,2,0)) -> true; abort.
true.
?- range(1,2,1) -> true; abort.
true.
?- range(1,2,2) -> true; abort.
true.
?- not(range(1,2,3)) -> true; abort.
true.
*/