ClojureDocs

Namespaces

Clojure/Conj 2026 — Charlotte, NC — Sept 30 - Oct 2 Learn More & Get Tickets →

clojure.core.logic

Core.logic is not provided as part of Clojure’s standard distribution, and must be included as a dependency.

Vars in clojure.core.logic

*^%

!=
Disequality constraint. Ensures that u and v will never unify. u and v can be complex terms.
->AnswerCache
Positional factory function for class clojure.core.logic.AnswerCache.
->Choice
Positional factory function for class clojure.core.logic.Choice.
->ConstraintStore
Positional factory function for class clojure.core.logic.ConstraintStore.
->LCons
Positional factory function for class clojure.core.logic.LCons.
->LVar
Positional factory function for class clojure.core.logic.LVar.
->Pair
Positional factory function for class clojure.core.logic.Pair.
->PMap
Positional factory function for class clojure.core.logic.PMap.
->Substitutions
Positional factory function for class clojure.core.logic.Substitutions.
->SubstValue
Positional factory function for class clojure.core.logic.SubstValue.
->SuspendedStream
Positional factory function for class clojure.core.logic.SuspendedStream.
==
A goal that attempts to unify terms u and v.

a

all
Like fresh but does does not create logic variables.
and*
A function version of all, which takes a list of goals and succeeds only fi they all succeed.
appendo
A relation where x, y, and z are proper collections, such that z is x appended to y

c

conda
Soft cut. Once the head of a clause has succeeded all other clauses will be ignored. Non-relational.
conde
Logical disjunction of the clauses. The first goal in a clause is considered the head of that clause. Interleaves the execution of the clauses.
condu
Committed choice. Once the head (first goal) of a clause has succeeded, remaining goals of the clause will only be run once. Non-relational.
conjo
A constraint version of conj
conso
A relation where l is a collection, such that a is the first of l and d is the rest of l. If ground d must be bound to a proper tail.
copy-term
Copies a term u into v. Non-relational.

d

defna
Define a soft cut goal. See conda.
defne
Define a goal fn. Supports pattern matching. All patterns will be tried. See conde.
defnu
Define a committed choice goal. See condu.
distincto
A relation which guarantees no element of l will unify with another element of l.

e

emptyo
A relation where a is the empty list
everyg
A pseudo-relation that takes a coll and ensures that the goal g succeeds on every element of the collection.

f

fail
A goal that always fails.
featurec
Ensure that a map contains at least the key-value pairs in the map fs. fs must be partially instantiated - that is, it may contain values which are logic variables to support feature extraction.
firsto
A relation where l is a collection, such that a is the first of l
fix-constraints
A goal to run the constraints in cq until it is empty. Of course running a constraint may grow cq so this function finds the fixpoint.
fna
Define an anonymous soft cut goal. See conda.
fnc
Define an anonymous constraint that can be used with the unifier: (let [oddc (fnc [x] (odd? x))] (unifier {:a '?a} {:a 1} :when {'?a oddc}) ;;=> {:a 1} (unifier {:a '?a} {:a 2} :when {'?a oddc}) ;;=> nil ) Note, the constraint will not run until all arguments are fully ground. Use defnc to define a constraint and assign a toplevel var.
fne
Define an anonymous goal fn. Supports pattern matching. All patterns will be tried. See conde.
fnu
Define an anonymous committed choice goal. See condu.
fresh
Creates fresh variables. Goals occuring within form a logical conjunction.

i

is
Set the value of a var to value of another var with the operation applied. Non-relational.

l

lcons
Constructs a sequence a with an improper tail d if d is a logic variable.
llist
Constructs a sequence from 2 or more arguments, with the last argument as the tail. The tail is improper if the last argument is a logic variable.
log
Goal for println
lvaro
A goal that succeeds if the argument is fresh. v must be a logic variable. Non-relational.

m

map->PMap
Factory function for class clojure.core.logic.PMap, taking a map of keywords to field values.
map->SubstValue
Factory function for class clojure.core.logic.SubstValue, taking a map of keywords to field values.
map->SuspendedStream
Factory function for class clojure.core.logic.SuspendedStream, taking a map of keywords to field values.
master
Take the argument to the goal and check that we don't have an alpha equivalent cached answer term in the cache. If it doesn't already exist in the cache add the new answer term.
matcha
Define a soft cut pattern match. See conda.
matche
Pattern matching macro. All patterns will be tried. See conde.
matchu
Define a committed choice goal. See condu.
member1o
Like membero but uses to disequality further constraining the results. For example, if x and l are ground and x occurs multiple times in l, member1o will succeed only once.
membero
A relation where l is a collection, such that l contains x.

n

nafc
EXPERIMENTAL: negation as failure constraint. All arguments to the goal c must be ground. If some argument is not ground the execution of this constraint will be delayed.
nilo
A relation where a is nil
nonlvaro
A goal that succeeds if the argument is not fresh. v must be a logic variable. Non-relational.

o

or*
A function version of conde, which takes a list of goals and tries them as if via conde. Note that or* only does disjunction, ie (or* [a b c]) is the same as (conde [a] [b] [c]). If you need something like (conde [a b] [c]), you can use and*, or all: (or* [(and* a b) c]).

p

partial-map
Given map m, returns partial map that unifies with maps even if it doesn't share all of the keys of that map.
permuteo
A relation that will permute xl into the yl. May not terminate if xl is not ground.
pred
Check a predicate against the value logic var. Non-relational.
project
Extract the values bound to the specified logic vars. Non-relational.

r

rembero
A relation between l and o where x is removed from l exactly one time.
resto
A relation where l is a collection, such that d is the rest of l
run
Executes goals until a maximum of n results are found.
run*
Executes goals until results are exhausted.
run-db
Executes goals until a maximum of n results are found. Uses a specified logic database.
run-db*
Executes goals until results are exhausted. Uses a specified logic database.
run-nc
Executes goals until a maximum of n results are found. Does not occurs-check.
run-nc*
Executes goals until results are exhausted. Does not occurs-check.

s

succeed
A goal that always succeeds.

t

tabled
Macro for defining a tabled goal. Prefer ^:tabled with the defne/a/u forms over using this directly.
trace-lvars
Goal for tracing the values of logic variables.
trace-s
Goal that prints the current substitution

w

waiting-stream-check
Take a waiting stream, a success continuation, and a failure continuation. If we don't find any ready suspended streams, invoke the failure continuation. If we find a ready suspended stream calculate the remainder of the waiting stream. If we've reached the fixpoint just call the thunk of the suspended stream, otherwise call mplus on the result of the thunk and the remainder of the waiting stream. Pass this result to the success contination.