Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested Prolog functions

Tags:

prolog

rotate(X):-
write('convert -rotate 90 '),write(X),write(' o.jpg'),
writeln(0).
beside(X,Y):-
write('convert -scale 50%%x50%% '),write(X),writeln(' 0111.jpg'),
write('convert -scale 50%%x50%% '),write(Y),writeln(' 01121.jpg'),
write('convert +append '),write(X),write(Y),writeln(' o.jpg').

above are my prolog codes for rotate and beside functions. How can i modify the codes to suit case like rotate(beside(X,Y)). which are nested

like image 707
bluedream Avatar asked Sep 20 '26 04:09

bluedream


1 Answers

You can't. That's because rotate and beside are not functions, they are predicates.

Functions return values and so you nest them – use the return value of one function as an input of another function. On the other hand, when you try to evaluate a predicate in Prolog, it tries to “unify” all its unbound parameters using the rules you gave it, and returns whether that succeeded and how.

Code like rotate(beside(X,Y)). is valued, but it doesn't mean what you think. It tries to evaluate the predicate rotate on a structure beside(X,Y). It doesn't try to evaluate the beside predicate.

like image 197
svick Avatar answered Sep 22 '26 14:09

svick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!