Rewrite datahike.query/bind-by-fn to return nil if not all symbols in the function call can be bound to values.
Add function datahike.tools/resolve-clauses.
Replace all occurrences in of (reduce -resolve-clause ...) by (dt/resolve-clauses ...) to handle the nil returned by datahike.query/bind-by-fn.
Add unit test that demonstrates that the bug has been fixed.
Discussion about the solution to issue 676:
The code in bind-by-fn is currently written in such a way that it assumes all symbols in the function call to be known in the context when the clause is evaluated but there are not checks to ensure that this is actually the case. Maybe there is a way to make it possible for symbols to be unknown but that would probably require a substantial rewrite of bind-by-fn. An easier way to address this problem is to make bind-by-fn return nil, instead of the new context, if not all symbols are known. However, this nil will consequently be returned by -resolve-clause and needs to be handled. We handle that nil by replacing all occurences of (reduce -resolve-clause ...) by (dt/resolve-clauses ...) to handle the nil and retry failed clauses in subsequent iterations.
Checks
Bugfix
[x] Related issues linked using fixes #number
[x] Integration tests added
[ ] Architecture Decision Record added if design changes necessary
SUMMARY
Fixes #676 using the following changes:
datahike.query/bind-by-fn
to return nil if not all symbols in the function call can be bound to values.datahike.tools/resolve-clauses
.(reduce -resolve-clause ...)
by(dt/resolve-clauses ...)
to handle thenil
returned bydatahike.query/bind-by-fn
.Discussion about the solution to issue 676: The code in
bind-by-fn
is currently written in such a way that it assumes all symbols in the function call to be known in the context when the clause is evaluated but there are not checks to ensure that this is actually the case. Maybe there is a way to make it possible for symbols to be unknown but that would probably require a substantial rewrite ofbind-by-fn
. An easier way to address this problem is to makebind-by-fn
returnnil
, instead of the new context, if not all symbols are known. However, thisnil
will consequently be returned by-resolve-clause
and needs to be handled. We handle thatnil
by replacing all occurences of(reduce -resolve-clause ...)
by(dt/resolve-clauses ...)
to handle the nil and retry failed clauses in subsequent iterations.Checks
Bugfix
fixes #number