Re: dynamic programming
"Richard A. O'Keefe" <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 2/09/2013, at 2:22 PM, Kilián Imre wrote: >> You are asking for the impossible. For one thing, >> when you write assert((a:b :- c)) you are *specifying* that >> the right hand calls are *NOT* made to the module 'a'. > > I am another opinion: I wasn't talking about opinion. When you write assert(( a:b :- c )) it *means* "define b in the a module to call c as if from this module I'm calling from." It doesn't matter whether there is a c in a: or not; it doesn't matter whether there is a c in the current module or not (if there isn't now, there might be by the time you call a:b). > I expect "assert((H:-B)), clause(H,B)" to work invariably under each circumstances. It's not completely clear to me what you mean here. For one thing, you have *never* in any Prolog textbook or standard been guaranteed that assert((H :- B)), clause(H, B) will always succeed. You are guaranteed that clause(H, B1) will give you a B1 that is _equivalent_ to B. So ?- H = a, B = ((b,c),d), assert((H :- B)), clause(H, B1), display(B), nl, display(B1), nl, B == B1. writes ,(,(b, c), d) ,(b, ,(c, d)) and then *fails*. B and B1 are not the *same* as terms, but they are *equivalent* as goals. In precisely the same way, ?- M = a, H = b, B = c, assert((M:H :- B)), clause(M:H, B1), display(B), nl, display(B1), nl, B == B1. writes c :(user,c) and then *fails*. B and B1 are not the *same* as terms, but they are *equivalent* as goals. So bearing in mind that assert+clause preserves *equivalence* of clause bodies as goals but not identity as terms, assert((H:-B)), clause(H,B) ***does*** "work invariably". You do in fact always get back something equivalent to what you asserted. > Just because of your explanation below: if I dont specify module prefix for call c, than it should take the default one, that is "a"... The default prefix, to the extent that the concept makes sense in Prolog, is "THE MODULE OF THE CALLER". a:assert((b :- c)) "Execute assert((b :- c)) as if it occurred in module a." assert(a:(b :- c)) "Assert the clause b :- c with the whole of it in the a: module, overriding the default module, which is that of the CALLER." assert((a:b :- c)) "Assert the clause a:b :- c with the default module being as it *always* is that of the caller, so the head is in module a and the body is in the caller's module." As a matter of fact, this last is something that's often needed: assert((hook_module:hook_predicate(Arguments) :- /*this module:*/my_hook_definition(Arguments))). The rule about module prefixes is a simple and uniform one: the "default" prefix is the module of the caller. You are asking that assert should be *inconsistent* with other module-sensitive predicates.