added soft cut

parent 75f91525
......@@ -31,6 +31,7 @@ PSSOURCES = \
logic/guile-log/match.scm \
logic/guile-log/undovar.scm \
logic/guile-log/interleave.scm \
logic/guile-log/soft-cut.scm \
logic/guile-log/run.scm \
logic/guile-log/tools.scm \
logic/guile-log/prompts.scm \
(define-module (logic guile-log soft-cut)
#:use-module (logic guile-log)
#:use-module (logic guile-log interleave)
#:export (soft-cut))
swi uses A *-> B ; C as a soft cut,
if A has at least one solution the result is A,B else \+A,C
The difficulty lies in that one need to mutate the failure depending if
one reaches A or not
note set! is magical in that it is macrofied to make sure it is guarded
and restored at reinstation of a state. the lgard adds it to the state list
and rgard removes it from the list going backwards reverses the actions.
(<define-guile-log-rule> (soft-if a b c)
(<let> ((p0 P)
(s0 S)
(cut1 CUT)
(cc CC)
(fr (<newframe>)))
(<let-with-lr-guard> wind lguard rguard
((rp (lambda ()
(<unwind> fr)
(parse<> (cut0 s0 p0 cc) c))))
(<with-fail> (lambda () rp)
(<with-cut> cut1
(<code> (set! rp p0))
(<let> ((cut2 CUT))
(<with-cut> cut2 c)))))))))))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment