added api to peek into closures

parent 9e1dc788
......@@ -1808,7 +1808,7 @@ We can insert scheme expressions with the construct @code{scm[sexp]}. You can in
Closures is an interesting construct a schemer can't stay away from and we support theme in guile-log. There is a complication with logic programs though, when we are comparing closures we compare code, they may differ, but still produce the same logic hence when there is a high demand to find all solutions, e.g. the predicate is closed, we may produce the wrong answer. Unfourtunately it's impossible to verify if the closures logically are the same or not and hence we will need to in some circumstances throw an error when such a unification is under action. Also when unifying closures we need to open up the closures and unify the state as well. We also support that quoted writes can read in the closures correctly with the straightforward logic of the logic beeing defined by the term. Also when we @code{assert*()} code that includes closures they will be compiled and handled just as with writes, e.g. the state of the code will be the world and connection outside that world will be lost e.g. in
@verbatim
f(X) :- Y=_,asserta(g :- {var(Y)}.),g.
f(X) :- Y=_,asserta(g :- {var(Y)=1}.),g.
@end verbatim
@code{Y} will be unbound although the @code{var(Y)} refers to the outside variable @code{Y}.
......
......@@ -5,4 +5,13 @@
prolog-closure-closure
prolog-closure-parent
prolog-closure-state
prolog-closure-closed?))
prolog-closure-closed?)
#:export (closure_p closure_state_ref closure_is_closed closure_code_ref))
(<define> (closure_p x) (when (prolog-closure? (<lookup> x))))
(<define> (closure_state_ref x l) (<=> l ,(prolog-closure-state (<lookup> x))))
(<define> (closure_is_closed x) (when (and (prolog-closure? (<lookup> x))
(prolog-closer-clsed (<lookup> x)))))
(<define> (closure_code_ref x l) (<=> l ,(prolog-closure-parent (<lookup> x))))
\ No newline at end of file
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