Rainer,
sorry for the delay in answering more extensively.
I'm interested in Ciao Prolog. You claim that Ciao Prolog does support programming with functions. What does this mean? Please be so kind and let me have some examples:
- I can define in Prolog "between(+,?,+)" : between(A,A,B) :- A =< B . between(A,X,B) :- A < B , A1 is A + 1 , between(A1,X,B) .
I'd prefer to write : between(A,A,B) :- A =< B . between(A,X,B) :- A < B , between(A + 1, X, B) .
Simply load into Ciao the following file (it works exactly as you have written it!):
:- module(_,_,[functions]).
between(A,A,B) :- A =< B . between(A,X,B) :- A < B , between(A + 1, X, B) .
- I can define in Prolog "flin(+,-)" : flin(X,Y) :- Y is 3*X + 5 .
I'd prefer to write : flin(X) := 3*X + 5 .
Simply add to the previous file:
flin(X) := 3*X + 5 .
And then, query:
?- flin(4,Y).
Y = 17 ?
(in fact, you can even express the "flin(+,-)" formally in the Ciao assertion language and this will be used by several tools, including LPdoc).
- I can define in Prolog "fak(+,-)" : fak(0,1). fak(N,Y) :- N > 0 , N1 is N - 1 , fak(N1,Y1), Y is N*Y1 .
I'd prefer to write : fak(0) := 1 . fak(N) := N*fak(N - 1) if N > 0 .
Simply add:
fak(0) := 1 . fak(N) := N* ~fak(N - 1) :- N > 0 .
The ~ is an 'eval' --the opposite of a 'quote'-- and it means that fak should be called, i.e., that it is not a data structure. You can also write
:- function fak/1.
fak(0) := 1 . fak(N) := N* fak(N - 1) :- N > 0 .
to avoid the need to use the ~.
- I can define in Prolog "fib(+,-)" : fib(0,0). fib(1,1). fib(X,Y) :- X > 1 , X2 is X - 2 , X1 is X - 1 , fib(X2,Y2) , fib(X1,Y1) , Y is Y2 + Y1 .
I'd prefer to write : fib(0) := 0 . fib(1) := 1 . fib(X) := fib(X - 2) + fib(X - 1) if X > 1 .
The only difference is that for consistency we use :- instead of 'if':
:- function fib/1.
fib(0) := 0 . fib(1) := 1 . fib(X) := fib(X - 2) + fib(X - 1) :- X > 1 .
or
fib(0) := 0 . fib(1) := 1 . fib(X) := ~fib(X - 2) + ~fib(X - 1) :- X > 1 .
- I can define in Prolog "divides(?,+)" : divides(X,Y) :- between(1,X,Y) , 0 is Y mod X .
I can ask the questions : ?- X is 3*4 , fak(3,Y) , fak(Y,Z) , divides(X,Z) . ?- fak(4,Y) , divides(X,Y) . ?- fib(4,X) , Y is 2*4 , fib(Y,Z) , divides(X,Z) . ?- fib(6,Y) , fib(Y,Z) , divides(X,Z) . I'd prefer to formulate : ?- divides( 3*4 , fak(fak(3)) ) . ?- divides( X , fak(4) ) . ?- divides( fib(4) , fib( 2*4 ) ) . ?- divides( X , fib(fib( 6 )) ) .
What you want here is to activate the functional syntax in the top level. This can be done in the a the natural manner:
?- use_package(functions). {Including /home/clip/lib/ciao/ciao-1.9/library/functions/functions.pl {Including /home/clip/lib/ciao/ciao-1.9/library/functions/ops.pl } }
yes ?- divides( 3*4 , ~fak(~fak(3)) ) .
yes ?- divides( X , ~fak(4) ) .
X = 1 ? yes ?- divides( ~fib(4) , ~fib( 2*4 ) ) .
yes ?- divides( X , ~fib(~fib( 6 )) ) .
X = 1 ? yes ?-
Is there a context sensitive help for built in predicates?
Yes! Simply do C-c TAB while in the development environment (i.e., after opening a .pl file with emacs).
Hope this helps!
The Ciao Development Team