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?

false
  • 10,264
  • 13
  • 101
  • 209
mrk
  • 3,061
  • 1
  • 29
  • 34

2 Answers2

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.

m09
  • 7,490
  • 3
  • 31
  • 58
  • 1
    Nit: Above is invalid syntax (try GNU to see this). It should be `(=>)/2` – false Apr 23 '12 at 14:48
  • @false: oh well, I hadn't any interpreter available to check that. Thanks, I'll edit :) – m09 Apr 23 '12 at 14:49
  • 1
    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. – false Apr 23 '12 at 14:57
  • @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 :) – m09 Apr 23 '12 at 15:21
  • Sooner or later you will need the standard - see [tag:iso-prolog] how to get it cheaply. – false Apr 23 '12 at 15:27
  • 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 :) – m09 Apr 23 '12 at 15:29
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.
false
  • 10,264
  • 13
  • 101
  • 209