<dynwind> added and also <continue> and <stall> added

parent c7c65069
......@@ -510,6 +510,7 @@ This is a sugar for essentially, @code{(<define> (f a ...) (<match> [#:mode +] (
@findex if
@findex <return>
@findex <ret>
@findex <dynwind>
@code{G.L. (<code> code ...)}, will execute @code{(begin code ...)} as scheme and then success.
......@@ -527,11 +528,15 @@ G.L. (if S X Y)
@code{G.L. (<ret> val)}, the same as @code{(<return> (u-scm val))}
@code{G.U. (<dynwind> redo-thunk undo-thunk)}, dynwind that when the unify stack is going in forward direction the redo-thunk is evaluated and else when we backtrack over this barrier the undo-thunk is evaluated.
@section go from scheme to guile-log
@findex <with-guile-log>
@findex <ask>
@findex <eval>
@findex <run>
@findex <stall>
@findex <continue>
@code{Scm (<with-guile-log> (p cc) code ...)}, this will start a guile-log session using failure think p and continuation @code{cc} and use @code{p} as a cut as well.
......@@ -543,6 +548,12 @@ G.L. (if S X Y)
@code{Scm (<run> n (v ...) code ...)}, bind @code{v ...} with variables and execute the code and collect the list of list of bindings of @code{v} at success if @code{(v ...) = (w)} then it will return a list of values. @code{n} is the maximum numbers of success results and skipping @code{n} results in no limit on the number of successes.
@code{G.L. (<stall>)}, this will stall a computation and allow it to continue at the users will and also be able to store the state.
@code{G.L. (<continue>)}, this will make it possible to continue a stalled run, but if the run opted out after n successes then must ask for the number of more successes as well by using:
@code{G.L. (<continue> n)}, with @code{n} the number of more successes to return.
@section Guile-log macro definitions
@findex define-guile-log
@findex guile-log-macro?
......
......@@ -7,11 +7,28 @@
<match> <=> <r=> <==> *r* <funcall>
<and!> <and!!> <succeeds>
<format> <tail-code> <code> <ret> <return>
<def> <<define>> <with-fail>
let<> <or!>)
<def> <<define>> <with-fail> <dynwind>
let<> <or!> <stall> <continue>)
(re-export define-guile-log guile-log-macro? log-code-macro log-code-macro?)
(define *cc* (gp-make-fluid))
(gp-fluid-set! *cc* #f)
(define (<stall> p cc)
(<return>
(set! *cc* (cons p cc))))
(define <continue>
(case-lambda
(() (if (and *cc* (car *cc*))
((cdr *cc*) (car *cc*))
#f))
((n) (if (and *cc* (integer? n) (not (car *cc*)))
((cdr *cc*) n)
'cannot-continue-and-take-n))))
(define-syntax <eval>
(syntax-rules ()
((_ (v ...) code fini cc)
......@@ -58,7 +75,13 @@
(if (= n 0)
(reverse ret)
(u-abort p)))
(reverse ret))))))
(let ((r (reverse ret)))
(set! ret '())
(gp-set! *cc* (cons #f (lambda (m)
(set! n m)
(u-abort p))))
r))))))
((_ m (v ...) code ...)
(let ((n m) (ret '()))
......@@ -71,7 +94,13 @@
(set! ret (cons (u-scm (list v ...)) ret))
(set! n (- n 1))
(if (= n 0)
(reverse ret)
(let ((r (reverse ret)))
(set! ret '())
(gp-set! *cc*
(cons #f (lambda (m)
(set! n m)
(u-abort p))))
r)
(u-abort p)))
(reverse ret))))))))
......@@ -659,6 +688,18 @@
(<match> (a ...)
(m ... (<cut> code)) ...)))))
(define-guile-log <dynwind>
(syntax-rules ()
((_ w redo undo)
(u-dynwind
redo
(lambda () (parse<> w <cc>))
undo))))
(log-code-macro '<dynwind>)
(include-from-path "logic/guile-log/interleave.scm")
......@@ -33,7 +33,7 @@
gp-make-fluid gp-fluid-set! gp-fluid-ref with-gp-fluids
u-prompt u-abort u-set! u-var! u-call u-deref gp-atomic?
u-context u-modded
u-unify! u-scm u-unify-raw! u-consu-dynwind umatch
u-unify! u-scm u-unify-raw! u-cons u-dynwind umatch
gp-copy))
......
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