We have:
(run* q
(fresh (x)
(==
`(,x)
q)))
In this case `(,x) is a list where the refrence to the variable x isn't quoted.
Does q unifies with a single element list?
Is the result (_0) because q unifies with the fresh variable x (even if it's in a list) or because it doesn't unify with anything at all? Or would in that case the result have been ()?
Yes.
(== (list x) q)is the same as(== q (list x)). Bothqandxare fresh before the execution of this unification goal (andqdoes not occur in(list x)). Afterwards, it is recorded in the substitution that the value ofqis(list x). No value forxis recorded.No,
qdoes not unify withx, but rather with a list containingx.When the final value of the whole
run*expression is returned, the variables are "reified", replaced with their values.xhas no value to be replaced with, so it is printed as_0, inside a list as it happens, which list is the value associated withq.The value of
(run* q ...)is a list of all valid assignments toq, as usual. There is only one such association, for the variableqand the value(list x).So
( (_0) )should be printed as the value of the(run* q ...)expression -- a list of one value forq, which is a list containing an uninstantiatedx, represented as a value_0.