algorithm,prolog,unification,iso-prolog

Third attempt. This is mainly a bugfix in a previous answer (which already had many modifications). Edit: 06/04/2015 When creating a more general term I was leaving both subterms as-is if either of them was a variable. Now I build a more general term for the "other" subterm in this...

error-handling,prolog,try-catch,iso-prolog,prolog-toplevel

I don't think that's an application programmer's job. Some Prolog systems already has this feature. For this particular case you can just create a predicate with "wrong" arity that outputs a message: fruit(_) :- write('Data should be entered in the format: \'fruit(X, Y)\' Please check your query and try again.'),...

module,prolog,iso-prolog,meta-predicate

Thats an interesting question. First I think there are two kinds of predicate_property/2 predicates. The first kind takes a callable and is intended to work smoothly with for example vanilla interpreters and built-ins such as write/1, nl/0, etc.., i.e.: solve((A,B)) :- !, solve(A), solve(B). solve(A) :- predicate_property(A, built_in), !, A....

One possibility: var_in_vars(V, Vs) :- \+ unify_with_occurs_check(V, Vs). and shorter: var_in_vars(V, Vs) :- \+ subsumes_term(V, Vs). EDIT: Future readers, please take into account the context of the question, which is a specific compactness challenge involving the expressivity of ISO predicates under given circumstances. In other circumstances, you will likely benefit...

prolog,operator-precedence,iso-prolog

Minor point: It's (^)/2 and not ^/2 to indicate that ^ is used as an operator and to make it valid Prolog syntax and a predicate indicator (7.1.6.6). (**)/2 and (^)/2 are both evaluable functors (9), so they can be used for Arithmetic evaluation (8.7) with (is)/2 and Arithmetic comparison...

The predicate nth0/3 is not part of ISO Prolog, so there is no explicit reference. However, the way how and when errors are reported is defined in the standard. In particular, type errors are never reported due to an argument being not sufficiently instantiated. The concrete formulation in the SWI...

Solution using term_variables/2: varset_union(VarSet1, VarSet2, Union):- term_variables([VarSet1|VarSet2], Union). varset_union(VarSets, Union):- term_variables(VarSets, Union). Solution using setof/3: varset_union(VarSet1, Varset2, Union):- varset_union([VarSet1, VarSet2], Union). varset_union([], []). varset_union(VarSets, Union):- setof(Var, VarSet^(member(VarSet, VarSets), member(Var, VarSet)), Union). ...

The solution I propose uses term_variables/2 to check if Bs has no extra variables over As and that As has no variable that doesn't appear in Bs. varset_seteq(As, Bs):- term_variables(As-Bs, As), term_variables(Bs-As, Bs). The above solution can be tricked to succeed with arguments that are not sets of free variables:...

module,prolog,standards,iso,iso-prolog

The system you cite, SWI-Prolog, is a system whose core is developed by a single developer. Such bold statements as those you quote are his very personal opinions. In the past, SWI did follow ISO standards for a certain period. Then, recently changed. If you want to read more about...

There is no such provision in ISO Prolog, neither to extend (is)/2 nor to rely on goal expansion. And, looking at the various implementation specific features that are offered by some implementations to this end, there is no generally agreed upon way to do this. So implementing your own (my_is)/2...

ISO/IEC 13211-1 has several requirements for integers, but a concrete representation is not required. If the integer representation is bounded, one of the following conditions holds 7.1.2 Integer ... minint = -(*minint) minint = -(maxint+1) Further, the evaluable functors listed in 9.4 Bitwise functors, that is (>>)/2, (<<)/2, (/\)/2, (\/)/2,...

From the documentation of floor/2 (http://www.eclipseclp.org/doc/bips/kernel/arithmetic/floor-2.html) The result type is the same as the argument type. To convert the type to integer, use integer/2. For example: ..., Floor is floor(Col+Row+1), Sum is integer(Floor). ...

Let me start with a simple implementation that works for many programs, but not all of them. Using catch/3 and throw/1 This method is definitely the simplest way to implement the cut in ISO Prolog. However, it is not very efficient. The basic idea is that cut simply succeeds, and...

prolog,time-complexity,iso-prolog

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...

prolog,iso-prolog,prolog-assert

You can do a trace to determine what happens: | ?- nice(_). 1 1 Call: nice(_17) ? 2 2 Call: asserta(nextBound(100)) ? 2 2 Exit: asserta(nextBound(100)) ? <-- 1st assert of netBound(100) succeeds 3 2 Call: retract(nextBound(10000)) ? 3 2 Exit: retract(nextBound(10000)) ? <-- retract nextBound(10000) succeeds 4 2 Call:...

write('\33\[1mbold\33\[0m'). That is, octal escape sequences (and hexadecimal which start with \x) need to be closed with a \ too. En revanche, a leading zero is not required, but possible. This is in no way specific to GNU, in fact, probably all systems close to ISO Prolog have it....

If term_variables/2 works in a time linear with the size of its first argument, then this might work: varset_intersection(As, Bs, As_cap_Bs):- term_variables([As, Bs], As_and_Bs), term_variables(As, SetAs), append(SetAs, OnlyBs, As_and_Bs), term_variables([OnlyBs, Bs], SetBs), append(OnlyBs, As_cap_Bs, SetBs). Each common variable appears only once in the result list no matter how many times...

prolog,iso-prolog,prolog-assert,jekejeke

assert/1 is not a standard predicate, although several implementations provide it. That doesn't seem to be the case for Jekejeke Prolog. Use instead either the asserta/1 or the assertz/1 standard predicates. The first asserts a clause as the first for the predicate. The latter asserts a clause as the last...