assert and retract in Shen Prolog

Skip to first unread message

Jul 27, 2023, 11:52:34 AMJul 27
to Shen
Theorem proving has been the ground for a lot of improvements in Shen Prolog; the garbage handler being one of them  that came in the S series.  I was experimenting with using assert and retract in this context.  Ironically, I did not need it in the later version of THORN.  

I had a beta version of these functions in S34.3, but dropped it in S34.4 because I thought the design was too clunky and reintroduced it back in S34.5 in a more streamlined form (about 50 loc vs 80 loc in the old version).   

In the new version, asserta and assertz are regular Shen functions (not Prolog calls) as is retract.  A dynamic predicate is a Prolog predicate that is the target of assert(a/z) or retract calls.   There is no need to declare a predicate to be dynamic.  The only thing to remember is that a predicate becomes dynamic when it is the target of an assert(a/z) call.

Dynamic predicates should be modified only by assert(a/z) and retract calls; not by defprolog.  The reason being is that Shen creates a skeleton Prolog procedure from which hangs a list of tagged Prolog procedure calls that access asserted  clauses.  Overwriting a dynamic procedure by hand-written Prolog will sever the connection to this list.

List notation is used to assert clauses.

(2-) (asserta [[mem X [cons X Y]] <--;])

(3-) (assertz [[mem X [cons _ Y]] <-- [mem X Y];])

(4-) (prolog? (mem X [1 2 3 4]))

(5-) (prolog? (mem 4 [1 2 3 4]))

(6-) (prolog? (mem 14 [1 2 3 4]))

(7-) (retract [[mem X [cons X Y]] <--;])
[[#<FUNCTION (LAMBDA (Y1143)) {23751AAD}> [mem X [cons _ Y]] <-- [mem X Y] ;]]

This returns the remnant of the list showing the remaining procedure and the associated clause.

(8-) (prolog? (mem 4 [1 2 3 4]))

S34.5 to go up soon.

Reply all
Reply to author
0 new messages