SWI-Prolog - Fail to Assert
Asked Answered
W

2

5

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?

Whittington answered 23/4, 2012 at 14:3 Comment(0)
I
5

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.

Impunity answered 23/4, 2012 at 14:15 Comment(6)
Nit: Above is invalid syntax (try GNU to see this). It should be (=>)/2Dioptase
@false: oh well, I hadn't any interpreter available to check that. Thanks, I'll edit :)Impunity
It's always like that: a predicate indicator has to have brackets if it has a corresponding operator definition. So it is (;)/2 and (',')/2. The quotes serve only to delimit a token - like 'a b' they are needed independently of operator declarations.Dioptase
@false: Ok! I encountered the notation in doc but didn't know if it was specific to SWI or the norm, thanks for those clarifications :)Impunity
Sooner or later you will need the standard - see iso-prolog how to get it cheaply.Dioptase
Yup I try to refer to it as soon as I have a doubt or have a choice between standard and non standard stuff. Though sometimes I just miss the fact that I'm using non standard stuff, so your clarifications help a lot in those cases :)Impunity
D
4

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.
Dioptase answered 23/4, 2012 at 14:55 Comment(4)
Right but I think it works if you are using Prolog interactively only! It does not work if you compile the file!!Whittington
Which Prolog system do you refer to? SWI, YAP, B, GNU are all the same.Dioptase
It's in the title (SWI-Prolog)Whittington
But apart from that: It is a good idea to use dynamic declarations.Dioptase

© 2022 - 2024 — McMap. All rights reserved.