Meaning of instantiation mode indicators in arguments of Prolog predicates

Those prefix operators, in this context, represent instantiation modes, i.e. they tell you which arguments should be variables or instantiated when calling the predicate. They also tell you if an argument will be (possibly further) instantiated by the call. They can also be used to tell you that an argument is going to be meta-interpreted … Read more

‘if’ in prolog?

Yes, there is such a control construct in ISO Prolog, called ->. You use it like this: ( condition -> then_clause ; else_clause ) Here is an example that uses a chain of else-if-clauses: ( X < 0 -> writeln(‘X is negative. That’s weird! Failing now.’), fail ; X =:= 0 -> writeln(‘X is zero.’) … Read more

Complexity of ISO Prolog predicates

tl;dr: No and no. Let’s start with sort/2 which ideally would need n ld(n) comparisons. Fine, but how long does one comparison take? Let’s try this out: tails(Es0, [Es0|Ess]) :- Es0 = [_|Es], tails(Es, Ess). tails([],[[]]). call_time(G,T) :- statistics(runtime,[T0|_]), G, statistics(runtime,[T1|_]), T is T1 – T0. | ?- between(12,15,I), N is 2^I, length(L,N),maplist(=(a),L), tails(L,LT), call_time(sort(LT,LTs), … Read more

Safer type tests in Prolog

The testing for types needs to distinguish itself from the traditional “type testing” built-ins that implicitly also test for a sufficient instantiation. So we effectively test only for sufficiently instantiated terms (si). And if they are not sufficiently instantiated, an appropriate error is issued. For a type nn, there is thus a type testing predicate … Read more