Added dynamic features section of the prolog api

parent 836173d3
......@@ -1834,11 +1834,57 @@ variables unifies and the code is equvalent. Also the system works with
@node prolog-dynamic-functions
@section Explaing the guile-log dynamic functions
a
Dynamic functions in guile-log prolog follows the iso prolog interface. But they are more powerful. They belong to a class of object that we can call dynamic objects for which dynamic features can be added how to backtrack store and restore state. The driving feature is that the state infromation is updated in a funcitonal manner and that its encapsulated with a thread safe handle. But the datastructure are not only functional, in order to have decent properties in prolog program and let them for example back track with the logic program we allow a mark and reset feature. To understand this scope please read about dynamic features. The dynamic functions are optimized for fast lookup and guile log prolog is fully indexed and can yield the matching items faster than it takes to actually perform any common match consequent. The target is for systems that update seldom and do lookup often. The dynamic functions @code{assert*} compainion will compile the program to bytecode/native for faster execution. Do not use dynamic functions as a hash table that updates often, for that use the hash table library. Also currently at most 10000 elements can be stored for a dynamic function. (The algorithm scales badly after that and we do not support larger than that).
@node dynamic-features
@section Dynamic features
a
A dynamic feature is a feature that can be added to the update flow of a dynamic variable, you may want it's state to be saved and restored when a continuation is stored and later executed. You may want the state to be started and restored in a more fine grained pattern when you do paralell. You may want the state to be restored when controls leaves a function either by sucessing or by back tracking and so on. Guile log sports the feature to allow all stateful data such as dynamic functions dynamic vlists, vhashes, operator tables, character translations, flags, and any functional datastructure you can think of that you define in guile scheme and exposed to prolog.
@subsection API.
There is a section about the scheme part of this interface, here we concentrate on the prolog part. The dynamin objects constructures will be defined in their associated library section, here we just describes what we can impose on them
@subsubsection backtracking versions
@code{backtrack_dynamic_object(o, ...)} Make sure that after this position and forward in the execution @code{o,...} will follow any backtracking and also backtrack to the value that they had at the junction unless a new dynamic feature is encountered.
@code{not_backtrack_dynamic_object(o, ...)} Make sure that after this position and forward in the execution @code{o,...} will not follow a backtracking unless a new dynamic feature is encountered.
@code{with_backtrack_dynamic_object(o, ...,code)} Make sure that inside @code{code} the execution @code{o,...} will follow any backtracking unless a new dynamic feature is encountered
@code{with_not_backtrack_dynamic_object(o, ...,code)} Make sure that inside @code{code} the execution @code{o,...} will not follow any backtracking unless a new dynamic feature is encountered
@subsubsection guarding states
@code{state_guard_dynamic_object(o, ...)}, A left limit for which state is restored if the state reinstated over the guard, unless other guards are encountered after this guard.
@code{state_guard_dynamic_object_zip(o, ...)}, A left limit for which state is restored if the state reinstated over the guard, unless other guards are encountered after this guard. The difference to the above is that this can be placed before a control construct that do parallell execution like interleaving disjunciton or zipping of goals. Hence we do not need to place it in each branch essentially meaning that when each branch is reinstated the dynamic objects value is reinstated for that branch else the control would not pass over the guard and no reinstation would result.
@code{always_state_guard_dynamic_object(o, ...)}, A left limit for which state is restored always independentof if the state reinstates over the guard, unless other guards are encountered after this guard.
@code{with_state_guard_dynamic_object(o,...,code)}, will guard the state only in @code{code}. But reinstation will not happen unless reinstation is from a backtracked state. That is if reinstation i essentially back tracking it will not restire the state.
@code{with_state_guard_dynamic_object_zip(o,...,code)}, will guard the state only in @code{code}. The same as above but the state will be reinstated when zip et all switches branches.
@code{with_always_state_guard_dynamic_object(o,....,code)}, ditto but inside @code{code} always reinstate state.
@subsubsection guarding values
@code{fluid_guard_dynamic_object(o,...)}, this will make sure that @code{o,...} is resetted to the value they had when the program passed over the guard, and reset to the value it had when control backttraced over it at reinstation over the guard.
@code{with_fluid_guard_dynamic_object(o,...,code)}, the same as above, but with an extra fluid guard at the success edge of @code{code}.
@code{with_fluid_guard_synamic_object_once(o,...,code)}, the same as above but takes an optimization by forcing the @code{code} to only succeeds once.
@subsubsection utils,
There are a few general util funcitons used to manage the state of the dynamic objects in a safe way.
@code{set_dynamic_object(m1 -> m2)}, the state @code{m1} state is transferd to @code{m2}
@code{copy_dynamic_object(m1 -> M2)}, @code{M2} will bind to a newly created object containing the state of @code{m1}.
Added ontop of this is how to evolve the state data like asserting new facts or to add a new pair on a map. But these operations is defined in each of the library sections.
@node prolog-libraries
@section Prolog libraries exposing guile-log features
......
......@@ -99,7 +99,7 @@ used it is then a safe journey.
(or (eq? h vlist-null)
(vhash? h))))))
(define* (mk-dynamic-funciton env #:optional (name #f))
(define* (mk-dynamic-function env #:optional (name #f))
(let* ((g #f)
(name (if name
name
......@@ -127,6 +127,16 @@ used it is then a safe journey.
nop
make-fluid
#:fail fail))
(define* (add-parameter-dynamics h const #:optional (fail (mkf 'parameter)))
(add-dynamic-object-features h
procedure?
'parameter-dynamics
(lambda (f) (f))
(lambda (f v) (f v))
nop
nop
const
#:fail fail))
(define* (add-vhash-dynamics h #:optional (fail (mkf 'vhash)))
(add-dynamic-object-features h
......
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