Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SWI-Prolog - Fail to Assert

I define an operator as follows:

:- op(500, xfx, =>).

When I try something like:

assert(a => b).

Prolog raises an error that says 'No permission to modify static_procedure (=>)/2'.

Any solution?

like image 700
mrk Avatar asked Apr 23 '12 14:04

mrk


People also ask

How do you assert in Prolog?

SWI-Prolog -- assert/1. Assert a clause (fact or rule) into the database. The predicate asserta/1 asserts the clause as first clause of the predicate while assertz/1 assert the clause as last clause. The deprecated assert/1 is equivalent to assertz/1.

What does the exclamation mark mean in Prolog?

Prolog provides a predicate that performs this function. It is called the cut, represented by an exclamation point (!). The cut effectively tells Prolog to freeze all the decisions made so far in this predicate. That is, if required to backtrack, it will automatically fail without trying other alternatives.

How do you end a loop in Prolog?

process_and_fail(end_of_file) :- !. process_and_fail(X) :- process(X), fail. The cut in process_file/1 is another example of terminating a generate-and-test loop. In general, a cut should always be placed after a repeat/0 so that the backtracking loop is clearly terminated.

Does Prolog have exception handling?

Exception handling in prolog is done with the catch function. We use it below to make sure we can open the requested file. The first parameter of catch is the Goal, or what we want to execute (comparable to a try in C or Java). The second parameter is what exception we want to catch.


2 Answers

As a security, you have to warn SWI that you are going to modify a predicate at runtime:

:- dynamic (=>)/2.

put at the top of the file should do it.

like image 54
m09 Avatar answered Oct 18 '22 19:10

m09


You must have meant another symbol in place of (=>)/2. Probably (->)/2 which is a control construct that cannot be modified.

Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 6.1.3-116-gf1c7e06)
...
?- asserta((a -> b)).
ERROR: asserta/1: No permission to modify static procedure `(->)/2'
ERROR: Defined at /opt/gupu/pl-devel/lib/swipl-6.1.3/boot/init.pl:194
?- op(500, xfx, =>).
true.

?- asserta(a => b).
true.
like image 4
false Avatar answered Oct 18 '22 19:10

false