Next: , Previous: , Up: Top   [Index]


3 Acumulators/generators

In the guile-log chapter we defined the basic framework to fold a sequence of solutions into a variable. With this we can support e.g prolog’s bagof and similar constructs. In the module (guile-log logic collects), we have defined a few specialisations of the fold operator in order to standardize these common abstractions.

3.1 Acumulators API

To explain the Api we have a gl-thunk, e.g. a guile-log lambda with zero arguments. it, will be the pattern to store. when it successes typically this variable will be copied and added to the resulting data structure which is list, sum, .... There is a possibility to keep some elements fixed and this is the -2 forms with the variable fixed naming the variable that needs to be fixated. e.g. first all solutions for the first found representation of the variable fixed will be found and added, then the then all solutions with the next found variant of the fixed will be used and so on, very much like how bagof in prolog is working. The -step versions of the acumulators will produce produce all the intermediate acumulator solutions.

The following forms will cons all solutions to a list e.g. prodice lists in reverse order.

G.L. (<collect> gl-thunk it list)

G.L. (<collect-2> gl-thunk it fixed list)

G.L. (<collect-step> gl-thunk it list)

G.L. (<collect-step-2> gl-thunk it fixed list)

——————————————————————–

The following forms will sum all solutions.

G.L. (<collect> gl-thunk it sum)

G.L. (<collect-2> gl-thunk it fixed sum)

G.L. (<collect-step> gl-thunk it sum)

G.L. (<collect-step-2> gl-thunk it fixed sum)

——————————————————————-

The following forms will take the product of all solutins

G.L. (<collect> gl-thunk it prod)

G.L. (<collect-2> gl-thunk it fixed prod)

G.L. (<collect-step> gl-thunk it prod)

G.L. (<collect-step-2> gl-thunk it fixed prod)

——————————————————————–

The following forms will take the max of all solutions.

G.L. (<max> gl-thunk it max)

G.L. (<max-2> gl-thunk it fixed max)

G.L. (<max-step> gl-thunk it max)

G.L. (<max-step-2> gl-thunk it fixed max)

——————————————————————–

The following forms will take the max of all solutions.

G.L. (<min> gl-thunk it min)

G.L. (<min-2> gl-thunk it fixed min)

G.L. (<min-step> gl-thunk it min)

G.L. (<min-step-2> gl-thunk it fixed min)

——————————————————————–

The following forms will take the and of all operations returning the last one as a solution.

G.L. (<soland> gl-thunk it and)

G.L. (<soland-2> gl-thunk it fixed and)

G.L. (<soland-step> gl-thunk it and)

G.L. (<soland-step-2> gl-thunk it fixed and)

——————————————————————–

The following forms will take the or of all operations returning the first solution.

G.L. (<solor> gl-thunk it or)

G.L. (<solor-2> gl-thunk it fixed or)

G.L. (<solor-step> gl-thunk it or)

G.L. (<solor-step-2> gl-thunk it fixed or)

3.2 Local Non backtracking Genrators API

This tool is found directly in the module (logic guile-log),

G.L. (<with-generators> ((var init) ...) code ...), This will bound the variables var ... initiated to init ... inside code ....

These variables can then be changed by using set! and if the updating is functional, the state of the variables will be managed and store and restore will be managed in such a way that jumping below the initiation with <with-generators> and back will produce the same values, but inside this form it will not be restored to the old value. Especially a simple generator can be applied by using,

G.L. (<next-generator-value> sum var val), e.g. perform var <- (sum var val) each time this line is executed and no backtracking will be done. ——————————————————————–


Next: , Previous: , Up: Top   [Index]