1
boolean(true).
boolean(false).
formula_0(P, Q):- (P; Q), \+ P.

solution_for_formula(P, Q, Formula):-
    maplist(boolean, [P, Q]), call([Formula, P, Q]).

A follow-up to my earlier question. Why wouldn't this work? (If I replace call([Formula, P, Q]) with formula_0(P, Q) it works.)

Community
  • 1
  • 1

1 Answers1

5

You want call(Formula, P, Q), not call([Formula, P, Q]). Simply remove the square brackets. Try this to make it more clear what the error is:

?- write_canonical(call([Formula, P, Q])).
call('.'(_,'.'(_,'.'(_,[]))))
true.

I.e. with the square brackets, you are calling a (.)/2 predicate, which you (likely) don't define. But the high-order predicate that you want to call is call/3, whose arguments are call(Closure, Arg1, Arg2). E.g. call(formula_0, true, false) will call formula_0(true, false).

Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
  • Thanks! That was actually the first thing I've tired, but the autocompletion played a trick with me, so I've got confused and searched further for different ways to denote a predicate. While searching I encountered a form: `[f, arg0, arg1, ...]`. Would you tell when this form is applicable? –  Oct 09 '13 at 11:12
  • 2
    Likely as argument to the `(=..)/2` standard predicate that allows you to convert between a term and its list representation. E.g. the call `foo(A,1) =.. [foo, A, 1]` is true. – Paulo Moura Oct 09 '13 at 11:16
  • Ah, thanks! Also, I found the reference, where I've found this form: http://en.wikibooks.org/wiki/Prolog/Higher_Order_Programming . –  Oct 09 '13 at 11:20
  • @wvxvw: Could you forward Paulo Moura's comments to this book? It is a pity if there is outdated material on the net. – false Oct 15 '13 at 19:10