Prolog Retract Error
Contents |
PceEmacs HTML generation License Publications TUTORIALS Beginner▶ Getting started Learn Prolog Now! Debugger Development tools Advanced▶ Modules Grammars (DCGs) clp(fd) Printing messages PlDoc Web applications▶ Web applications Let's Encrypt! Graphics▶ XPCE GUI error no linux options Semantic web▶ RDF namespaces External collections▶ Meta level tutorials For packagers▶ no permission to modify static procedure op 3 Linux packages COMMUNITY IRC Forum News Mail list Report a bug Submit a patch Submit an add-on Roadmap External
Prolog Assert Example
links Contributors SWI-Prolog items USERS Semantic web Students Researchers Commercial users Dog food Is SWIPL right for me? WIKI Login Edit this page View changes Sandbox Wiki help All tags
No Permission To Modify Static Procedure Length 2
This message happens is there are clauses for Name/Arity in your program and you try to modify this predicate using assert/1, retract/1 or a related predicate. What is wrong? Normally, compiled code results in static predicates. These cannot be modified at runtime. Knowing code is static helps the compiler. If you want to make dynamic code, i.e., code that can be prolog dynamic modified ar runtime, use the dynamic/1 directive. Normally you place this directive near the start of a file or just above the code: :- dynamic arc/2. arc(a, b). arc(a, c). ... Generally it is not a very good idea to load dynamic data as program data. If some rule depends partly on static data and partly on dynamic define them as separate predicates and write a predicate combining the two types of data properly: :- dynamic user_arc/2. arc(A, B) :- user_arc(A, B). arc(A, B) :- predifined_arc(A, B). predifined_arc(a, b). ... Though assert/1 on a not-yet-existent predicate creates the predicate as dynamic, it is good practice to declare all dynamic code using the dynamic/1 directive. Abolish is evil The predicate abolish/1 deletes all traces of a predicate from the program: its clauses, its attributes (dynamic, multifile, meta) and its source-information. Normally you just want to delete the clauses, so you use retractall/1, e.g.: ..., retractall(arc(,)), See also ReadDynamicFromFile Tag confusing pages with doc-needs-help|Tags are associated to your profile if you are logged in Tags: login to add a new annotation post. login Powere
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company
Prolog Dynamic Example
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions error no 2147467259 Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, prolog examples just like you, helping each other. Join them; it only takes a minute: Sign up SWI-Prolog - Fail to Assert up vote 6 down vote favorite 1 I define an operator as follows: :- op(500, xfx, http://www.swi-prolog.org/FAQ/DynamicCode.html =>). When I try something like: assert(a => b). Prolog raises an error that says 'No permission to modify static_procedure (=>)/2'. Any solution? prolog prolog-assert share|improve this question edited Jan 26 '14 at 0:42 false 10k651107 asked Apr 23 '12 at 14:03 saadtaame 1,59711222 add a comment| 2 Answers 2 active oldest votes up vote 6 down vote accepted As a security, you have to warn SWI that you are going to modify a http://stackoverflow.com/questions/10282088/swi-prolog-fail-to-assert predicate at runtime: :- dynamic (=>)/2. put at the top of the file should do it. share|improve this answer edited Apr 23 '12 at 14:49 answered Apr 23 '12 at 14:15 m09 5,61711650 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 iso-prolog how to get it cheaply. –false Apr 23 '12 at 15:27 | show 2 more comments up vote 5 down vote You must have meant another symbol in place of (=>)/2. Probably (->)/2 which is a control construct that cannot be modified. Welcome to SWI-Prolo
the first clause that matches the argument from the database. On backtracking, http://www.cs.uni-potsdam.de/wv/lehre/Material/Prolog/Eclipse-Doc/bips/kernel/dynamic/retract-1.html successive clauses that match are removed. The clauses are not reasserted when backtracking occurs through retract/1. The functor of the head of Clause must be that of a predicate declared as dynamic, otherwise an error occurs. If no clause matches, it fails. retract/1 satisfies the logical update semantics. error no When retract/1 is first called, it makes a virtual copy of the clauses that match and, on backtracking, unifies its argument with them and removes them from the database. Any modifications made to the procedure after retract/1 has started executing do not, in any way, affect its behaviour. no permission to A subsequent call, however, makes and uses a new, virtual, copy of the modified database. Fail Conditions Fails if no dynamic clause unifies with Clause Resatisfiable Yes Exceptions (4) instantiation fault Clause is not instantiated (4) instantiation fault The head of Clause is a free variable. (5) type error Clause or the head of Clause is not a callable term. (63) procedure not dynamic Procedure is not dynamic (70) accessing an undefined dynamic procedure Procedure is undefined Examples Success: [eclipse]: assert(city(munich)), assert(city(london)), assert((p :- write(hi), write(there))). yes. [eclipse]: retract(city(X)). X = munich More? (;) yes. [eclipse]: retract(city(X) :- Body). X = london Body = true yes. [eclipse]: retract(p :- Body). Body = write(hi) , write(there) yes. Fail: assert(fact),retract(fact),retract(fact). Error: retract(X). (Error 4). retract("x"). (Error 5). retract(listing). (Error 63). retract(undef). (Error 70). See Also asserta / 1, dynamic / 1, listing / 1