No matching definitions.

tur/backtrack-dfs

stdlib/backtrack-dfs.tur

depth-first search driver over the backtracking trail.

defn

dfs-succeed

(dfs-succeed :)

the goal with exactly one solution and no bindings.

A goal that calls `k` once and propagates its verdict.

(dfs-solve (dfs-succeed) (fn [] true))  ; => 1

Since: SX2

defn

dfs-fail

(dfs-fail :)

the goal with no solutions.

A goal that never calls `k` and reports exhaustion.

(dfs-solve (dfs-fail) (fn [] true))  ; => 0

Since: SX2

defn

dfs-and

(dfs-and [^fat g1 : (fn [(fn [])

conjunction: g2 runs inside each solution of g1.

g1the outer goal
g2the inner goal, tried under each of g1's solutions

The conjoined goal.

(dfs-and (dfs-set x 1) (dfs-set y 2))   ; one solution: x=1, y=2

Since: SX2

defn

dfs-or

(dfs-or [^fat g1 : (fn [(fn [])

disjunction: g1's alternatives fully exhausted, then g2's.

g1tried first, depth-first
g2tried after g1 is exhausted

The disjoined goal.

(dfs-or (dfs-set x 1) (dfs-set x 2))   ; two solutions

Since: SX2

defn

dfs-guard

(dfs-guard [^fat pred : (fn [])

succeed with no bindings iff `pred` holds NOW.

predevaluated when the search reaches this goal

A goal with one solution when pred is true, none otherwise.

(dfs-and (dfs-choose-int x 1 3)
           (dfs-guard (fn [] (> (bt-get x) 1))))   ; x=2, x=3

Since: SX2

defn

dfs-set

(dfs-set [c : BtCell v : int] :)

bind a trailed cell to a value.

cthe cell
vthe value

A goal with one solution (the binding) or none (refused write).

Since: SX2

defn

dfs-choose-go

(dfs-choose-go [c : BtCell lo : int hi : int ^fat k : (fn [])

internal: try binding c to each of lo..hi in order.

defn

dfs-choose-int

(dfs-choose-int [c : BtCell lo : int hi : int] :)

nondeterministically bind `c` to an integer in [lo, hi].

cthe cell to bind
lofirst candidate (inclusive)
hilast candidate (inclusive)

A goal with up to (hi - lo + 1) solutions.

(dfs-choose-int x 1 8)   ; x = 1, then 2, ... then 8

Since: SX2

defn

dfs-solve

(dfs-solve [^fat goal : (fn [(fn [])

run a goal depth-first; count solutions.

goalthe goal to run
on-solutionreifier + continuation verdict, run per solution

The number of solutions on-solution saw.

(dfs-solve (dfs-choose-int x 1 3)
             (fn [] (do (println (bt-get x)) true)))   ; prints 1 2 3 => 3

Carries `#fx{Bt}`: this is the entry point that actually runs the search
and so brackets, writes and unwinds the trail. The goal CONSTRUCTORS above
(`dfs-set`, `dfs-choose-int`, ...) do not carry it -- they only build a
closure, and the trail is touched when that closure runs, which is here.

Since: SX2