Skip to content

Commit 32d2c15

Browse files
committed
docs(solver): document method to check if a program or a query admits at least one solution
1 parent 2adbe77 commit 32d2c15

File tree

1 file changed

+11
-1
lines changed
  • src/main/scala/io/github/kelvindev15/prolog/solver

1 file changed

+11
-1
lines changed

src/main/scala/io/github/kelvindev15/prolog/solver/Solver.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ trait Solver:
3939
def admitsSolutions(program: PrologProgram): Boolean =
4040
val solutions = solve(program)
4141
solutions.hasNext && solutions.next().isInstanceOf[Solution.Yes]
42-
42+
4343
object Solver:
4444
/** A mapping from [[Variable]]s to [[Term]]s */
4545
type Substitution = Map[Variable, Term]
@@ -147,12 +147,22 @@ object Solver:
147147
): LazyList[Solution] =
148148
solver lazySolve (PrologProgram.emptyTheory withGoal query)
149149

150+
/** Returns true if the program admits at least one solution.
151+
*
152+
* @param solver the solver that should be used.
153+
* @param program the program to solve.
154+
*/
150155
def hasSolutionForProgram(using solver: Solver = tuPrologSolver())(
151156
program: PrologProgram
152157
): Boolean =
153158
val solutions = solve(program)
154159
solutions.hasNext && solutions.next().isInstanceOf[Solution.Yes]
155160

161+
/** Returns true if the program admits at least one solution.
162+
*
163+
* @param solver the solver that should be used.
164+
* @param goal the program to satisfy.
165+
*/
156166
def hasSolutionForGoal(using solver: Solver = tuPrologSolver())(
157167
goal: Term
158168
): Boolean = hasSolutionForProgram(PrologProgram.emptyTheory withGoal goal)

0 commit comments

Comments
 (0)