1

I'm using JPL and launch some queries to Swi-Prolog. The program works fine with all queries, but one.

This query is not working:

assert(like(X, Y) :- element(I, [1, 2, 3], X), element(I, [2, 3, 4], Y) ).

Exception in thread "main" jpl.PrologException: PrologException: error(uninstantiation_error(element(_3, '.'(2, '.'(3, '.'(4, []))), _4)), context(:(system, /(assert, 2)), '2-nd argument'))

If I put the query in a .pl fle (without assert, obvisously) and run it with consult, works fine! But if I type the query in console mode, return the same error like JPL. So, where is the problem?

user840718
  • 1,563
  • 6
  • 29
  • 54

1 Answers1

1

You are very near to get the illumination. It will not work neither on console ! Then you will try to change the syntax. Understanding the Prolog operator model, try

?- assert((like(X, Y) :- element(I, [1, 2, 3], X), element(I, [2, 3, 4], Y))).

and it will work!

Your problem was the precedence of operator (:-)/2 WRT operator (,)/2.

CapelliC
  • 59,646
  • 5
  • 47
  • 90
  • Well! It's working with just 2 brackets....but, I don't understand why. The problem is the number od the argument, or the bad use od the (:-)/2 operator? With 3 arguments...I have to add more brackets? – user840718 Jun 22 '13 at 23:34
  • Prolog use operators like :- or , as configurable syntax sugar on terms - or better - structs. And you don't need to add more brackets. Just two will make all the expression a :- b,c,d 'fitting' in – CapelliC Jun 22 '13 at 23:42